<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class File - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-File-label-About+the+Examples">About the Examples</a>
    <li><a href="#class-File-label-Access+Modes">Access Modes</a>
    <li><a href="#class-File-label-String+Access+Modes">String Access Modes</a>
    <li><a href="#class-File-label-Read-2FWrite+Mode">Read/Write Mode</a>
    <li><a href="#class-File-label-Read-2FWrite+Modes+for+Existing+File">Read/Write Modes for Existing File</a>
    <li><a href="#class-File-label-Read-2FWrite+Modes+for+File+To+Be+Created">Read/Write Modes for File To Be Created</a>
    <li><a href="#class-File-label-Data+Mode">Data Mode</a>
    <li><a href="#class-File-label-File-Create+Mode">File-Create Mode</a>
    <li><a href="#class-File-label-Integer+Access+Modes">Integer Access Modes</a>
    <li><a href="#class-File-label-File-Create+Mode+Specified+as+an+Integer">File-Create Mode Specified as an Integer</a>
    <li><a href="#class-File-label-Data+Mode+Specified+as+an+Integer">Data Mode Specified as an Integer</a>
    <li><a href="#class-File-label-Encodings">Encodings</a>
    <li><a href="#class-File-label-File+Permissions">File Permissions</a>
    <li><a href="#class-File-label-File+Constants">File Constants</a>
    <li><a href="#class-File-label-What-27s+Here">What’s Here</a>
    <li><a href="#class-File-label-Creating">Creating</a>
    <li><a href="#class-File-label-Querying">Querying</a>
    <li><a href="#class-File-label-Settings">Settings</a>
    <li><a href="#class-File-label-Other">Other</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="IO.html">IO</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-absolute_path">::absolute_path</a>
    <li ><a href="#method-c-absolute_path-3F">::absolute_path?</a>
    <li ><a href="#method-c-atime">::atime</a>
    <li ><a href="#method-c-basename">::basename</a>
    <li ><a href="#method-c-birthtime">::birthtime</a>
    <li ><a href="#method-c-blockdev-3F">::blockdev?</a>
    <li ><a href="#method-c-chardev-3F">::chardev?</a>
    <li ><a href="#method-c-chmod">::chmod</a>
    <li ><a href="#method-c-chown">::chown</a>
    <li ><a href="#method-c-ctime">::ctime</a>
    <li ><a href="#method-c-delete">::delete</a>
    <li ><a href="#method-c-directory-3F">::directory?</a>
    <li ><a href="#method-c-dirname">::dirname</a>
    <li ><a href="#method-c-empty-3F">::empty?</a>
    <li ><a href="#method-c-executable-3F">::executable?</a>
    <li ><a href="#method-c-executable_real-3F">::executable_real?</a>
    <li ><a href="#method-c-exist-3F">::exist?</a>
    <li ><a href="#method-c-expand_path">::expand_path</a>
    <li ><a href="#method-c-extname">::extname</a>
    <li ><a href="#method-c-file-3F">::file?</a>
    <li ><a href="#method-c-fnmatch">::fnmatch</a>
    <li ><a href="#method-c-fnmatch-3F">::fnmatch?</a>
    <li ><a href="#method-c-ftype">::ftype</a>
    <li ><a href="#method-c-grpowned-3F">::grpowned?</a>
    <li ><a href="#method-c-identical-3F">::identical?</a>
    <li ><a href="#method-c-join">::join</a>
    <li ><a href="#method-c-lchmod">::lchmod</a>
    <li ><a href="#method-c-lchown">::lchown</a>
    <li ><a href="#method-c-link">::link</a>
    <li ><a href="#method-c-lstat">::lstat</a>
    <li ><a href="#method-c-lutime">::lutime</a>
    <li ><a href="#method-c-mkfifo">::mkfifo</a>
    <li ><a href="#method-c-mtime">::mtime</a>
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-open">::open</a>
    <li ><a href="#method-c-owned-3F">::owned?</a>
    <li ><a href="#method-c-path">::path</a>
    <li ><a href="#method-c-pipe-3F">::pipe?</a>
    <li ><a href="#method-c-readable-3F">::readable?</a>
    <li ><a href="#method-c-readable_real-3F">::readable_real?</a>
    <li ><a href="#method-c-readlink">::readlink</a>
    <li ><a href="#method-c-realdirpath">::realdirpath</a>
    <li ><a href="#method-c-realpath">::realpath</a>
    <li ><a href="#method-c-rename">::rename</a>
    <li ><a href="#method-c-setgid-3F">::setgid?</a>
    <li ><a href="#method-c-setuid-3F">::setuid?</a>
    <li ><a href="#method-c-size">::size</a>
    <li ><a href="#method-c-size-3F">::size?</a>
    <li ><a href="#method-c-socket-3F">::socket?</a>
    <li ><a href="#method-c-split">::split</a>
    <li ><a href="#method-c-stat">::stat</a>
    <li ><a href="#method-c-sticky-3F">::sticky?</a>
    <li ><a href="#method-c-symlink">::symlink</a>
    <li ><a href="#method-c-symlink-3F">::symlink?</a>
    <li ><a href="#method-c-truncate">::truncate</a>
    <li ><a href="#method-c-umask">::umask</a>
    <li ><a href="#method-c-unlink">::unlink</a>
    <li ><a href="#method-c-utime">::utime</a>
    <li ><a href="#method-c-world_readable-3F">::world_readable?</a>
    <li ><a href="#method-c-world_writable-3F">::world_writable?</a>
    <li ><a href="#method-c-writable-3F">::writable?</a>
    <li ><a href="#method-c-writable_real-3F">::writable_real?</a>
    <li ><a href="#method-c-zero-3F">::zero?</a>
    <li ><a href="#method-i-atime">#atime</a>
    <li ><a href="#method-i-birthtime">#birthtime</a>
    <li ><a href="#method-i-chmod">#chmod</a>
    <li ><a href="#method-i-chown">#chown</a>
    <li ><a href="#method-i-ctime">#ctime</a>
    <li ><a href="#method-i-flock">#flock</a>
    <li ><a href="#method-i-lstat">#lstat</a>
    <li ><a href="#method-i-mtime">#mtime</a>
    <li ><a href="#method-i-size">#size</a>
    <li ><a href="#method-i-truncate">#truncate</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-File">
    <h1 id="class-File" class="class">
      class File
    </h1>

    <section class="description">
    
<p>A File object is a representation of a file in the underlying platform.</p>

<p>Class File extends module <a href="FileTest.html"><code>FileTest</code></a>, supporting such singleton methods as <code>File.exist?</code>.</p>

<h3 id="class-File-label-About+the+Examples">About the Examples<span><a href="#class-File-label-About+the+Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Many examples here use these variables:</p>

<pre class="ruby"><span class="ruby-comment"># English text with newlines.</span>
<span class="ruby-identifier">text</span> = <span class="ruby-identifier">&lt;&lt;~EOT</span>
<span class="ruby-value">  First line
  Second line

  Fourth line
  Fifth line
</span><span class="ruby-identifier">EOT</span>

<span class="ruby-comment"># Russian text.</span>
<span class="ruby-identifier">russian</span> = <span class="ruby-string">&quot;\u{442 435 441 442}&quot;</span> <span class="ruby-comment"># =&gt; &quot;тест&quot;</span>

<span class="ruby-comment"># Binary data.</span>
<span class="ruby-identifier">data</span> = <span class="ruby-string">&quot;\u9990\u9991\u9992\u9993\u9994&quot;</span>

<span class="ruby-comment"># Text file.</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;t.txt&#39;</span>, <span class="ruby-identifier">text</span>)

<span class="ruby-comment"># File with Russian text.</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;t.rus&#39;</span>, <span class="ruby-identifier">russian</span>)

<span class="ruby-comment"># File with binary data.</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;wb:UTF-16&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">data</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
</pre>

<h2 id="class-File-label-Access+Modes">Access Modes<span><a href="#class-File-label-Access+Modes">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Methods <a href="File.html#method-c-new"><code>File.new</code></a> and <a href="File.html#method-c-open"><code>File.open</code></a> each create a File object for a given file path.</p>

<h3 id="class-File-label-String+Access+Modes">String Access Modes<span><a href="#class-File-label-String+Access+Modes">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Methods <a href="File.html#method-c-new"><code>File.new</code></a> and <a href="File.html#method-c-open"><code>File.open</code></a> each may take string argument <code>mode</code>, which:</p>
<ul><li>
<p>Begins with a 1- or 2-character <a href="File.html#class-File-label-Read-2FWrite+Mode">read/write mode</a>.</p>
</li><li>
<p>May also contain a 1-character <a href="File.html#class-File-label-Data+Mode">data mode</a>.</p>
</li><li>
<p>May also contain a 1-character <a href="File.html#class-File-label-File-Create+Mode">file-create mode</a>.</p>
</li></ul>

<h4 id="class-File-label-Read-2FWrite+Mode">Read/Write Mode<span><a href="#class-File-label-Read-2FWrite+Mode">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>The read/write <code>mode</code> determines:</p>
<ul><li>
<p>Whether the file is to be initially truncated.</p>
</li><li>
<p>Whether reading is allowed, and if so:</p>
<ul><li>
<p>The initial read position in the file.</p>
</li><li>
<p>Where in the file reading can occur.</p>
</li></ul>
</li><li>
<p>Whether writing is allowed, and if so:</p>
<ul><li>
<p>The initial write position in the file.</p>
</li><li>
<p>Where in the file writing can occur.</p>
</li></ul>
</li></ul>

<p>These tables summarize:</p>

<pre>Read/Write Modes for Existing File

|------|-----------|----------|----------|----------|-----------|
| R/W  | Initial   |          | Initial  |          | Initial   |
| Mode | Truncate? |  Read    | Read Pos |  Write   | Write Pos |
|------|-----------|----------|----------|----------|-----------|
| &#39;r&#39;  |    No     | Anywhere |    0     |   Error  |     -     |
| &#39;w&#39;  |    Yes    |   Error  |    -     | Anywhere |     0     |
| &#39;a&#39;  |    No     |   Error  |    -     | End only |    End    |
| &#39;r+&#39; |    No     | Anywhere |    0     | Anywhere |     0     |
| &#39;w+&#39; |    Yes    | Anywhere |    0     | Anywhere |     0     |
| &#39;a+&#39; |    No     | Anywhere |   End    | End only |    End    |
|------|-----------|----------|----------|----------|-----------|

Read/Write Modes for \File To Be Created

|------|----------|----------|----------|-----------|
| R/W  |          | Initial  |          | Initial   |
| Mode |  Read    | Read Pos |  Write   | Write Pos |
|------|----------|----------|----------|-----------|
| &#39;w&#39;  |   Error  |    -     | Anywhere |     0     |
| &#39;a&#39;  |   Error  |    -     | End only |     0     |
| &#39;w+&#39; | Anywhere |    0     | Anywhere |     0     |
| &#39;a+&#39; | Anywhere |    0     | End only |    End    |
|------|----------|----------|----------|-----------|</pre>

<p>Note that modes <code>&#39;r&#39;</code> and <code>&#39;r+&#39;</code> are not allowed for a non-existent file (exception raised).</p>

<p>In the tables:</p>
<ul><li>
<p><code>Anywhere</code> means that methods <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, and <a href="IO.html#method-i-seek"><code>IO#seek</code></a> may be used to change the file’s position, so that allowed reading or writing may occur anywhere in the file.</p>
</li><li>
<p><code>End only</code> means that writing can occur only at end-of-file, and that methods <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, and <a href="IO.html#method-i-seek"><code>IO#seek</code></a> do not affect writing.</p>
</li><li>
<p><code>Error</code> means that an exception is raised if disallowed reading or writing is attempted.</p>
</li></ul>

<h5 id="class-File-label-Read-2FWrite+Modes+for+Existing+File">Read/Write Modes for Existing File<span><a href="#class-File-label-Read-2FWrite+Modes+for+Existing+File">&para;</a> <a href="#top">&uarr;</a></span></h5>
<ul><li>
<p><code>&#39;r&#39;</code>:</p>
<ul><li>
<p><a href="File.html"><code>File</code></a> is not initially truncated:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.txt&#39;</span>) <span class="ruby-comment"># =&gt; #&lt;File:t.txt&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>           <span class="ruby-comment"># =&gt; false</span>
</pre>
</li><li>
<p>File’s initial read position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be read anywhere; see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;First line\n&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;Second line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;First line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">1</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;irst line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">1</span>, <span class="ruby-value">:CUR</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;econd line\n&quot;</span>
</pre>
</li><li>
<p>Writing is not allowed:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>) <span class="ruby-comment"># Raises IOError.</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;w&#39;</code>:</p>
<ul><li>
<p><a href="File.html"><code>File</code></a> is initially truncated:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">text</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;w&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-comment"># =&gt; true</span>
</pre>
</li><li>
<p>File’s initial write position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be written anywhere (even past end-of-file); see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foo&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazfoo&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-3</span>, <span class="ruby-value">:END</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bam&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbam&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">8</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bah&#39;</span>)  <span class="ruby-comment"># Zero padding as needed.</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbam\u0000\u0000bah&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 11</span>
</pre>
</li><li>
<p>Reading is not allowed:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># Raises IOError.</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;a&#39;</code>:</p>
<ul><li>
<p><a href="File.html"><code>File</code></a> is not initially truncated:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;a&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-comment"># =&gt; false</span>
</pre>
</li><li>
<p>File’s initial position is 0 (but is ignored):</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be written only at end-of-file; <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a> do not affect writing:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobarbaz&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bat&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobarbazbat&quot;</span>
</pre>
</li><li>
<p>Reading is not allowed:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># Raises IOError.</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;r+&#39;</code>:</p>
<ul><li>
<p><a href="File.html"><code>File</code></a> is not initially truncated:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">text</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;r+&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-comment"># =&gt; false</span>
</pre>
</li><li>
<p>File’s initial read position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be read or written anywhere (even past end-of-file); see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;First line\n&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;Second line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;First line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">1</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;irst line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">1</span>, <span class="ruby-value">:CUR</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment"># =&gt; &quot;econd line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;WWW&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-comment"># =&gt; &quot;WWWst line\nSecond line\nFourth line\nFifth line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">10</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;XXX&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-comment"># =&gt; &quot;WWWst lineXXXecond line\nFourth line\nFifth line\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-6</span>, <span class="ruby-value">:END</span>)
<span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;YYY&#39;</span>)
<span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-comment"># =&gt; #&lt;File:t.tmp&gt;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-comment"># =&gt; &quot;WWWst lineXXXecond line\nFourth line\nFifth YYYe\n&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">2</span>, <span class="ruby-value">:END</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;ZZZ&#39;</span>) <span class="ruby-comment"># Zero padding as needed.</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-comment"># =&gt; &quot;WWWst lineXXXecond line\nFourth line\nFifth YYYe\n\u0000\u0000ZZZ&quot;</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;a+&#39;</code>:</p>
<ul><li>
<p><a href="File.html"><code>File</code></a> is not initially truncated:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;a+&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-comment"># =&gt; false</span>
</pre>
</li><li>
<p>File’s initial read position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be written only at end-of-file; <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a> do not affect writing:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)      <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)      <span class="ruby-comment"># =&gt; &quot;foobarbaz&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bat&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobarbazbat&quot;</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be read anywhere; see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;foobarbazbat&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;barbazbat&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-3</span>, <span class="ruby-value">:END</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;bat&quot;</span>
</pre>
</li></ul>
</li></ul>

<h5 id="class-File-label-Read-2FWrite+Modes+for+File+To+Be+Created">Read/Write Modes for File To Be Created<span><a href="#class-File-label-Read-2FWrite+Modes+for+File+To+Be+Created">&para;</a> <a href="#top">&uarr;</a></span></h5>

<p>Note that modes <code>&#39;r&#39;</code> and <code>&#39;r+&#39;</code> are not allowed for a non-existent file (exception raised).</p>
<ul><li>
<p><code>&#39;w&#39;</code>:</p>
<ul><li>
<p>File’s initial write position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_f</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;w&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be written anywhere (even past end-of-file); see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foo&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazfoo&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-3</span>, <span class="ruby-value">:END</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bam&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbam&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">8</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bah&#39;</span>)  <span class="ruby-comment"># Zero padding as needed.</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbam\u0000\u0000bah&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 11</span>
</pre>
</li><li>
<p>Reading is not allowed:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># Raises IOError.</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;a&#39;</code>:</p>
<ul><li>
<p>File’s initial write position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_f</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;a&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p>Writing occurs only at end-of-file:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobarbaz&quot;</span>
</pre>
</li><li>
<p>Reading is not allowed:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># Raises IOError.</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;w+&#39;</code>:</p>
<ul><li>
<p>File’s initial position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_f</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;w+&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be written anywhere (even past end-of-file); see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foo&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbar&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazfoo&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-3</span>, <span class="ruby-value">:END</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bam&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbam&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">8</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bah&#39;</span>)  <span class="ruby-comment"># Zero padding as needed.</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;bazbam\u0000\u0000bah&quot;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 11</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be read anywhere (even past end-of-file); see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span>
<span class="ruby-comment"># =&gt; &quot;bazbam\u0000\u0000bah&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">3</span>
<span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span>
<span class="ruby-comment"># =&gt; &quot;bam\u0000\u0000bah&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-3</span>, <span class="ruby-value">:END</span>)
<span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span>
<span class="ruby-comment"># =&gt; &quot;bah&quot;</span>
</pre>
</li></ul>
</li><li>
<p><code>&#39;a+&#39;</code>:</p>
<ul><li>
<p>File’s initial write position is 0:</p>

<pre class="ruby"><span class="ruby-identifier">path</span> = <span class="ruby-string">&#39;t.tmp&#39;</span>
<span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_f</span>(<span class="ruby-identifier">path</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>, <span class="ruby-string">&#39;a+&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 0</span>
</pre>
</li><li>
<p>Writing occurs only at end-of-file:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;foo&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;bar&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> <span class="ruby-comment"># =&gt; 6</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobar&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;baz&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>) <span class="ruby-comment"># =&gt; &quot;foobarbaz&quot;</span>
</pre>
</li><li>
<p><a href="File.html"><code>File</code></a> may be read anywhere (even past end-of-file); see <a href="IO.html#method-i-rewind"><code>IO#rewind</code></a>, <a href="IO.html#method-i-pos-3D"><code>IO#pos=</code></a>, <a href="IO.html#method-i-seek"><code>IO#seek</code></a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;foobarbaz&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">3</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;barbaz&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">seek</span>(<span class="ruby-value">-3</span>, <span class="ruby-value">:END</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;baz&quot;</span>

<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">800</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment"># =&gt; &quot;&quot;</span>
</pre>
</li></ul>
</li></ul>

<h4 id="class-File-label-Data+Mode">Data Mode<span><a href="#class-File-label-Data+Mode">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>To specify whether data is to be treated as text or as binary data, either of the following may be suffixed to any of the string read/write modes above:</p>
<ul><li>
<p><code>&#39;t&#39;</code>: Text data; sets the default external encoding to <code>Encoding::UTF_8</code>; on Windows, enables conversion between EOL and CRLF and enables interpreting <code>0x1A</code> as an end-of-file marker.</p>
</li><li>
<p><code>&#39;b&#39;</code>: Binary data; sets the default external encoding to <code>Encoding::ASCII_8BIT</code>; on Windows, suppresses conversion between EOL and CRLF and disables interpreting <code>0x1A</code> as an end-of-file marker.</p>
</li></ul>

<p>If neither is given, the stream defaults to text data.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.txt&#39;</span>, <span class="ruby-string">&#39;rt&#39;</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;rb&#39;</span>)
</pre>

<p>When the data mode is specified, the read/write mode may not be omitted, and the data mode must precede the file-create mode, if given:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;b&#39;</span>)   <span class="ruby-comment"># Raises an exception.</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;rxb&#39;</span>) <span class="ruby-comment"># Raises an exception.</span>
</pre>

<h4 id="class-File-label-File-Create+Mode">File-Create Mode<span><a href="#class-File-label-File-Create+Mode">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>The following may be suffixed to any writable string mode above:</p>
<ul><li>
<p><code>&#39;x&#39;</code>: Creates the file if it does not exist; raises an exception if the file exists.</p>
</li></ul>

<p>Example:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-string">&#39;wx&#39;</span>)
</pre>

<p>When the file-create mode is specified, the read/write mode may not be omitted, and the file-create mode must follow the data mode:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;x&#39;</span>)   <span class="ruby-comment"># Raises an exception.</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;rxb&#39;</span>) <span class="ruby-comment"># Raises an exception.</span>
</pre>

<h3 id="class-File-label-Integer+Access+Modes">Integer Access Modes<span><a href="#class-File-label-Integer+Access+Modes">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>When mode is an integer it must be one or more of the following constants, which may be combined by the bitwise OR operator <code>|</code>:</p>
<ul><li>
<p><code>File::RDONLY</code>: Open for reading only.</p>
</li><li>
<p><code>File::WRONLY</code>: Open for writing only.</p>
</li><li>
<p><code>File::RDWR</code>: Open for reading and writing.</p>
</li><li>
<p><code>File::APPEND</code>: Open for appending only.</p>
</li></ul>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.txt&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">RDONLY</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">RDWR</span> <span class="ruby-operator">|</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span> <span class="ruby-operator">|</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">EXCL</span>)
</pre>

<p>Note: <a href="Method.html"><code>Method</code></a> <a href="IO.html#method-i-set_encoding"><code>IO#set_encoding</code></a> does not allow the mode to be specified as an integer.</p>

<h3 id="class-File-label-File-Create+Mode+Specified+as+an+Integer">File-Create Mode Specified as an Integer<span><a href="#class-File-label-File-Create+Mode+Specified+as+an+Integer">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>These constants may also be ORed into the integer mode:</p>
<ul><li>
<p><code>File::CREAT</code>: Create file if it does not exist.</p>
</li><li>
<p><code>File::EXCL</code>: Raise an exception if <code>File::CREAT</code> is given and the file exists.</p>
</li></ul>

<h3 id="class-File-label-Data+Mode+Specified+as+an+Integer">Data Mode Specified as an Integer<span><a href="#class-File-label-Data+Mode+Specified+as+an+Integer">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Data mode cannot be specified as an integer. When the stream access mode is given as an integer, the data mode is always text, never binary.</p>

<p>Note that although there is a constant <code>File::BINARY</code>, setting its value in an integer stream mode has no effect; this is because, as documented in <a href="File/File/Constants.html"><code>File::Constants</code></a>, the <code>File::BINARY</code> value disables line code conversion, but does not change the external encoding.</p>

<h3 id="class-File-label-Encodings">Encodings<span><a href="#class-File-label-Encodings">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Any of the string modes above may specify encodings - either external encoding only or both external and internal encodings - by appending one or both encoding names, separated by colons:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;rb&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">external_encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:ASCII-8BIT&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">internal_encoding</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;rb:UTF-16&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">external_encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:UTF-16 (dummy)&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">internal_encoding</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.dat&#39;</span>, <span class="ruby-string">&#39;rb:UTF-16:UTF-16&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">external_encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:UTF-16 (dummy)&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">internal_encoding</span> <span class="ruby-comment"># =&gt; #&lt;Encoding:UTF-16&gt;</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
</pre>

<p>The numerous encoding names are available in array <a href="Encoding.html#method-c-name_list"><code>Encoding.name_list</code></a>:</p>

<pre class="ruby"><span class="ruby-constant">Encoding</span>.<span class="ruby-identifier">name_list</span>.<span class="ruby-identifier">take</span>(<span class="ruby-value">3</span>) <span class="ruby-comment"># =&gt; [&quot;ASCII-8BIT&quot;, &quot;UTF-8&quot;, &quot;US-ASCII&quot;]</span>
</pre>

<p>When the external encoding is set, strings read are tagged by that encoding when reading, and strings written are converted to that encoding when writing.</p>

<p>When both external and internal encodings are set, strings read are converted from external to internal encoding, and strings written are converted from internal to external encoding. For further details about transcoding input and output, see <a href="encodings_rdoc.html#label-Encodings">Encodings</a>.</p>

<p>If the external encoding is <code>&#39;BOM|UTF-8&#39;</code>, <code>&#39;BOM|UTF-16LE&#39;</code> or <code>&#39;BOM|UTF16-BE&#39;</code>, Ruby checks for a Unicode BOM in the input document to help determine the encoding. For UTF-16 encodings the file open mode must be binary. If the BOM is found, it is stripped and the external encoding from the BOM is used.</p>

<p>Note that the BOM-style encoding option is case insensitive, so <code>&#39;bom|utf-8&#39;</code> is also valid.</p>

<h2 id="class-File-label-File+Permissions">File Permissions<span><a href="#class-File-label-File+Permissions">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>A File object has <em>permissions</em>, an octal integer representing the permissions of an actual file in the underlying platform.</p>

<p>Note that file permissions are quite different from the <em>mode</em> of a file stream (File object).</p>

<p>In a File object, the permissions are available thus, where method <code>mode</code>, despite its name, returns permissions:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.txt&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">lstat</span>.<span class="ruby-identifier">mode</span>.<span class="ruby-identifier">to_s</span>(<span class="ruby-value">8</span>) <span class="ruby-comment"># =&gt; &quot;100644&quot;</span>
</pre>

<p>On a Unix-based operating system, the three low-order octal digits represent the permissions for owner (6), group (4), and world (4). The triplet of bits in each octal digit represent, respectively, read, write, and execute permissions.</p>

<p>Permissions <code>0644</code> thus represent read-write access for owner and read-only access for group and world. See man pages <a href="https://www.unix.com/man-page/bsd/2/open">open(2)</a> and <a href="https://www.unix.com/man-page/bsd/2/chmod">chmod(2)</a>.</p>

<p>For a directory, the meaning of the execute bit changes: when set, the directory can be searched.</p>

<p>Higher-order bits in permissions may indicate the type of file (plain, directory, pipe, socket, etc.) and various other special features.</p>

<p>On non-Posix operating systems, permissions may include only read-only or read-write, in which case, the remaining permission will resemble typical values. On Windows, for instance, the default permissions are <code>0644</code>; The only change that can be made is to make the file read-only, which is reported as <code>0444</code>.</p>

<p>For a method that actually creates a file in the underlying platform (as opposed to merely creating a File object), permissions may be specified:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span>, <span class="ruby-value">0644</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span>, <span class="ruby-value">0444</span>)
</pre>

<p>Permissions may also be changed:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span>, <span class="ruby-value">0444</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-value">0644</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-value">0444</span>)
</pre>

<h2 id="class-File-label-File+Constants">File Constants<span><a href="#class-File-label-File+Constants">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Various constants for use in File and <a href="IO.html"><code>IO</code></a> methods may be found in module <a href="File/File/Constants.html"><code>File::Constants</code></a>; an array of their names is returned by <code>File::Constants.constants</code>.</p>

<h2 id="class-File-label-What-27s+Here">What’s Here<span><a href="#class-File-label-What-27s+Here">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>First, what’s elsewhere. Class File:</p>
<ul><li>
<p>Inherits from <a href="IO.html#class-IO-label-What-27s+Here">class IO</a>, in particular, methods for creating, reading, and writing files</p>
</li><li>
<p>Includes module <a href="FileTest.html"><code>FileTest</code></a>, which provides dozens of additional methods.</p>
</li></ul>

<p>Here, class File provides methods that are useful for:</p>
<ul><li>
<p><a href="File.html#class-File-label-Creating">Creating</a></p>
</li><li>
<p><a href="File.html#class-File-label-Querying">Querying</a></p>
</li><li>
<p><a href="File.html#class-File-label-Settings">Settings</a></p>
</li><li>
<p><a href="File.html#class-File-label-Other">Other</a></p>
</li></ul>

<h3 id="class-File-label-Creating">Creating<span><a href="#class-File-label-Creating">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="File.html#method-c-new"><code>::new</code></a>: Opens the file at the given path; returns the file.</p>
</li><li>
<p><a href="File.html#method-c-open"><code>::open</code></a>: Same as <a href="File.html#method-c-new"><code>::new</code></a>, but when given a block will yield the file to the block, and close the file upon exiting the block.</p>
</li><li>
<p><a href="File.html#method-c-link"><code>::link</code></a>: Creates a new name for an existing file using a hard link.</p>
</li><li>
<p><a href="File.html#method-c-mkfifo"><code>::mkfifo</code></a>: Returns the FIFO file created at the given path.</p>
</li><li>
<p><a href="File.html#method-c-symlink"><code>::symlink</code></a>: Creates a symbolic link for the given file path.</p>
</li></ul>

<h3 id="class-File-label-Querying">Querying<span><a href="#class-File-label-Querying">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p><em>Paths</em></p>
<ul><li>
<p><a href="File.html#method-c-absolute_path"><code>::absolute_path</code></a>: Returns the absolute file path for the given path.</p>
</li><li>
<p><a href="File.html#method-c-absolute_path-3F"><code>::absolute_path?</code></a>: Returns whether the given path is the absolute file path.</p>
</li><li>
<p><a href="File.html#method-c-basename"><code>::basename</code></a>: Returns the last component of the given file path.</p>
</li><li>
<p><a href="File.html#method-c-dirname"><code>::dirname</code></a>: Returns all but the last component of the given file path.</p>
</li><li>
<p><a href="File.html#method-c-expand_path"><code>::expand_path</code></a>: Returns the absolute file path for the given path, expanding <code>~</code> for a home directory.</p>
</li><li>
<p><a href="File.html#method-c-extname"><code>::extname</code></a>: Returns the file extension for the given file path.</p>
</li><li>
<p><a href="File.html#method-c-fnmatch-3F"><code>::fnmatch?</code></a> (aliased as <a href="File.html#method-c-fnmatch"><code>::fnmatch</code></a>): Returns whether the given file path matches the given pattern.</p>
</li><li>
<p><a href="File.html#method-c-join"><code>::join</code></a>: Joins path components into a single path string.</p>
</li><li>
<p><a href="File.html#method-c-path"><code>::path</code></a>: Returns the string representation of the given path.</p>
</li><li>
<p><a href="File.html#method-c-readlink"><code>::readlink</code></a>: Returns the path to the file at the given symbolic link.</p>
</li><li>
<p><a href="File.html#method-c-realdirpath"><code>::realdirpath</code></a>: Returns the real path for the given file path, where the last component need not exist.</p>
</li><li>
<p><a href="File.html#method-c-realpath"><code>::realpath</code></a>: Returns the real path for the given file path, where all components must exist.</p>
</li><li>
<p><a href="File.html#method-c-split"><code>::split</code></a>: Returns an array of two strings: the directory name and basename of the file at the given path.</p>
</li><li>
<p><a href="IO.html#method-i-path"><code>path</code></a> (aliased as <a href="IO.html#method-i-to_path"><code>to_path</code></a>):  Returns the string representation of the given path.</p>
</li></ul>

<p><em>Times</em></p>
<ul><li>
<p><a href="File.html#method-c-atime"><code>::atime</code></a>: Returns a <a href="Time.html"><code>Time</code></a> for the most recent access to the given file.</p>
</li><li>
<p><a href="File.html#method-c-birthtime"><code>::birthtime</code></a>: Returns a <a href="Time.html"><code>Time</code></a>  for the creation of the given file.</p>
</li><li>
<p><a href="File.html#method-c-ctime"><code>::ctime</code></a>: Returns a <a href="Time.html"><code>Time</code></a>  for the metadata change of the given file.</p>
</li><li>
<p><a href="File.html#method-c-mtime"><code>::mtime</code></a>: Returns a <a href="Time.html"><code>Time</code></a> for the most recent data modification to the content of the given file.</p>
</li><li>
<p><a href="File.html#method-i-atime"><code>atime</code></a>: Returns a <a href="Time.html"><code>Time</code></a> for the most recent access to <code>self</code>.</p>
</li><li>
<p><a href="File.html#method-i-birthtime"><code>birthtime</code></a>: Returns a <a href="Time.html"><code>Time</code></a>  the creation for <code>self</code>.</p>
</li><li>
<p><a href="File.html#method-i-ctime"><code>ctime</code></a>: Returns a <a href="Time.html"><code>Time</code></a> for the metadata change of <code>self</code>.</p>
</li><li>
<p><a href="File.html#method-i-mtime"><code>mtime</code></a>: Returns a <a href="Time.html"><code>Time</code></a> for the most recent data modification to the content of <code>self</code>.</p>
</li></ul>

<p><em>Types</em></p>
<ul><li>
<p><a href="File.html#method-c-blockdev-3F"><code>::blockdev?</code></a>: Returns whether the file at the given path is a block device.</p>
</li><li>
<p><a href="File.html#method-c-chardev-3F"><code>::chardev?</code></a>: Returns whether the file at the given path is a character device.</p>
</li><li>
<p><a href="File.html#method-c-directory-3F"><code>::directory?</code></a>: Returns whether the file at the given path is a directory.</p>
</li><li>
<p><a href="File.html#method-c-executable-3F"><code>::executable?</code></a>: Returns whether the file at the given path is executable by the effective user and group of the current process.</p>
</li><li>
<p><a href="File.html#method-c-executable_real-3F"><code>::executable_real?</code></a>: Returns whether the file at the given path is executable by the real user and group of the current process.</p>
</li><li>
<p><a href="File.html#method-c-exist-3F"><code>::exist?</code></a>: Returns whether the file at the given path exists.</p>
</li><li>
<p><a href="File.html#method-c-file-3F"><code>::file?</code></a>: Returns whether the file at the given path is a regular file.</p>
</li><li>
<p><a href="File.html#method-c-ftype"><code>::ftype</code></a>: Returns a string giving the type of the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-grpowned-3F"><code>::grpowned?</code></a>: Returns whether the effective group of the current process owns the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-identical-3F"><code>::identical?</code></a>: Returns whether the files at two given paths are identical.</p>
</li><li>
<p><a href="File.html#method-c-lstat"><code>::lstat</code></a>: Returns the <a href="File/Stat.html"><code>File::Stat</code></a> object for the last symbolic link in the given path.</p>
</li><li>
<p><a href="File.html#method-c-owned-3F"><code>::owned?</code></a>: Returns whether the effective user of the current process owns the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-pipe-3F"><code>::pipe?</code></a>: Returns whether the file at the given path is a pipe.</p>
</li><li>
<p><a href="File.html#method-c-readable-3F"><code>::readable?</code></a>: Returns whether the file at the given path is readable by the effective user and group of the current process.</p>
</li><li>
<p><a href="File.html#method-c-readable_real-3F"><code>::readable_real?</code></a>: Returns whether the file at the given path is readable by the real user and group of the current process.</p>
</li><li>
<p><a href="File.html#method-c-setgid-3F"><code>::setgid?</code></a>: Returns whether the setgid bit is set for the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-setuid-3F"><code>::setuid?</code></a>: Returns whether the setuid bit is set for the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-socket-3F"><code>::socket?</code></a>: Returns whether the file at the given path is a socket.</p>
</li><li>
<p><a href="File.html#method-c-stat"><code>::stat</code></a>: Returns the <a href="File/Stat.html"><code>File::Stat</code></a> object for the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-sticky-3F"><code>::sticky?</code></a>: Returns whether the file at the given path has its sticky bit set.</p>
</li><li>
<p><a href="File.html#method-c-symlink-3F"><code>::symlink?</code></a>: Returns whether the file at the given path is a symbolic link.</p>
</li><li>
<p><a href="File.html#method-c-umask"><code>::umask</code></a>: Returns the umask value for the current process.</p>
</li><li>
<p><a href="File.html#method-c-world_readable-3F"><code>::world_readable?</code></a>: Returns whether the file at the given path is readable by others.</p>
</li><li>
<p><a href="File.html#method-c-world_writable-3F"><code>::world_writable?</code></a>: Returns whether the file at the given path is writable by others.</p>
</li><li>
<p><a href="File.html#method-c-writable-3F"><code>::writable?</code></a>: Returns whether the file at the given path is writable by the effective user and group of the current process.</p>
</li><li>
<p><a href="File.html#method-c-writable_real-3F"><code>::writable_real?</code></a>: Returns whether the file at the given path is writable by the real user and group of the current process.</p>
</li><li>
<p><a href="File.html#method-i-lstat"><code>lstat</code></a>: Returns the <a href="File/Stat.html"><code>File::Stat</code></a> object for the last symbolic link in the path for <code>self</code>.</p>
</li></ul>

<p><em>Contents</em></p>
<ul><li>
<p><a href="File.html#method-c-empty-3F"><code>::empty?</code></a> (aliased as <a href="File.html#method-c-zero-3F"><code>::zero?</code></a>): Returns whether the file at the given path exists and is empty.</p>
</li><li>
<p><a href="File.html#method-c-size"><code>::size</code></a>: Returns the size (bytes) of the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-size-3F"><code>::size?</code></a>: Returns <code>nil</code> if there is no file at the given path, or if that file is empty; otherwise returns the file size (bytes).</p>
</li><li>
<p><a href="File.html#method-i-size"><code>size</code></a>: Returns the size (bytes) of <code>self</code>.</p>
</li></ul>

<h3 id="class-File-label-Settings">Settings<span><a href="#class-File-label-Settings">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="File.html#method-c-chmod"><code>::chmod</code></a>: Changes permissions of the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-chown"><code>::chown</code></a>: Change ownership of the file at the given path.</p>
</li><li>
<p><a href="File.html#method-c-lchmod"><code>::lchmod</code></a>: Changes permissions of the last symbolic link in the given path.</p>
</li><li>
<p><a href="File.html#method-c-lchown"><code>::lchown</code></a>: Change ownership of the last symbolic in the given path.</p>
</li><li>
<p><a href="File.html#method-c-lutime"><code>::lutime</code></a>: For each given file path, sets the access time and modification time of the last symbolic link in the path.</p>
</li><li>
<p><a href="File.html#method-c-rename"><code>::rename</code></a>: Moves the file at one given path to another given path.</p>
</li><li>
<p><a href="File.html#method-c-utime"><code>::utime</code></a>: Sets the access time and modification time of each file at the given paths.</p>
</li><li>
<p><a href="File.html#method-i-flock"><code>flock</code></a>: Locks or unlocks <code>self</code>.</p>
</li></ul>

<h3 id="class-File-label-Other">Other<span><a href="#class-File-label-Other">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="File.html#method-c-truncate"><code>::truncate</code></a>: Truncates the file at the given file path to the given size.</p>
</li><li>
<p><a href="File.html#method-c-unlink"><code>::unlink</code></a> (aliased as <a href="File.html#method-c-delete"><code>::delete</code></a>): Deletes the file for each given file path.</p>
</li><li>
<p><a href="File.html#method-i-truncate"><code>truncate</code></a>: Truncates <code>self</code> to the given size.</p>
</li></ul>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="ALT_SEPARATOR">ALT_SEPARATOR
          <dd><p>platform specific alternative separator</p>
          <dt id="PATH_SEPARATOR">PATH_SEPARATOR
          <dd><p>path list separator</p>
          <dt id="SEPARATOR">SEPARATOR
          <dd><p>separates directory parts in path</p>
          <dt id="Separator">Separator
          <dd><p>separates directory parts in path</p>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-absolute_path" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          absolute_path(file_name [, dir_string] )  &rarr;  abs_file_name
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless <em>dir_string</em> is given, in which case it will be used as the starting point. If the given pathname starts with a “<code>~</code>” it is NOT expanded, it is treated as a normal directory name.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">absolute_path</span>(<span class="ruby-string">&quot;~oracle/bin&quot;</span>)       <span class="ruby-comment">#=&gt; &quot;&lt;relative_path&gt;/~oracle/bin&quot;</span>
</pre>

                              <div class="method-source-code" id="absolute_path-source">
            <pre>static VALUE
s_absolute_path(int c, const VALUE * v, VALUE _)
{
    return rb_file_s_absolute_path(c, v);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-absolute_path-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          absolute_path?(file_name)  &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>file_name</code> is an absolute path, and <code>false</code> otherwise.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">absolute_path?</span>(<span class="ruby-string">&quot;c:/foo&quot;</span>)     <span class="ruby-comment">#=&gt; false (on Linux), true (on Windows)</span>
</pre>

                              <div class="method-source-code" id="absolute_path-3F-source">
            <pre>static VALUE
s_absolute_path_p(VALUE klass, VALUE fname)
{
    VALUE path = rb_get_path(fname);

    if (!rb_is_absolute_path(RSTRING_PTR(path))) return Qfalse;
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-atime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          atime(file_name)  &rarr;  time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last access time for the named file as a <a href="Time.html"><code>Time</code></a> object.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">atime</span>(<span class="ruby-string">&quot;testfile&quot;</span>)   <span class="ruby-comment">#=&gt; Wed Apr 09 08:51:48 CDT 2003</span>
</pre>

                              <div class="method-source-code" id="atime-source">
            <pre>static VALUE
rb_file_s_atime(VALUE klass, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) {
        int e = errno;
        FilePathValue(fname);
        rb_syserr_fail_path(e, fname);
    }
    return stat_atime(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-basename" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          basename(file_name [, suffix] )  &rarr;  base_name
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last component of the filename given in <em>file_name</em> (after first stripping trailing separators), which can be formed using both <a href="File.html#SEPARATOR"><code>File::SEPARATOR</code></a> and <a href="File.html#ALT_SEPARATOR"><code>File::ALT_SEPARATOR</code></a> as the separator when <a href="File.html#ALT_SEPARATOR"><code>File::ALT_SEPARATOR</code></a> is not <code>nil</code>. If <em>suffix</em> is given and present at the end of <em>file_name</em>, it is removed. If <em>suffix</em> is “.*”, any extension will be removed.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-string">&quot;/home/gumby/work/ruby.rb&quot;</span>)          <span class="ruby-comment">#=&gt; &quot;ruby.rb&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-string">&quot;/home/gumby/work/ruby.rb&quot;</span>, <span class="ruby-string">&quot;.rb&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;ruby&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-string">&quot;/home/gumby/work/ruby.rb&quot;</span>, <span class="ruby-string">&quot;.*&quot;</span>)    <span class="ruby-comment">#=&gt; &quot;ruby&quot;</span>
</pre>

                              <div class="method-source-code" id="basename-source">
            <pre>static VALUE
rb_file_s_basename(int argc, VALUE *argv, VALUE _)
{
    VALUE fname, fext, basename;
    const char *name, *p;
    long f, n;
    rb_encoding *enc;

    fext = Qnil;
    if (rb_check_arity(argc, 1, 2) == 2) {
        fext = argv[1];
        StringValue(fext);
        enc = check_path_encoding(fext);
    }
    fname = argv[0];
    FilePathStringValue(fname);
    if (NIL_P(fext) || !(enc = rb_enc_compatible(fname, fext))) {
        enc = rb_enc_get(fname);
        fext = Qnil;
    }
    if ((n = RSTRING_LEN(fname)) == 0 || !*(name = RSTRING_PTR(fname)))
        return rb_str_new_shared(fname);

    p = ruby_enc_find_basename(name, &amp;f, &amp;n, enc);
    if (n &gt;= 0) {
        if (NIL_P(fext)) {
            f = n;
        }
        else {
            const char *fp;
            fp = StringValueCStr(fext);
            if (!(f = rmext(p, f, n, fp, RSTRING_LEN(fext), enc))) {
                f = n;
            }
            RB_GC_GUARD(fext);
        }
        if (f == RSTRING_LEN(fname)) return rb_str_new_shared(fname);
    }

    basename = rb_str_new(p, f);
    rb_enc_copy(basename, fname);
    return basename;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-birthtime" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">birthtime</span><span
                                class="method-args">(p1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="birthtime-source">
            <pre>RUBY_FUNC_EXPORTED VALUE
rb_file_s_birthtime(VALUE klass, VALUE fname)
{
    statx_data st;

    if (rb_statx(fname, &amp;st, STATX_BTIME) &lt; 0) {
        int e = errno;
        FilePathValue(fname);
        rb_syserr_fail_path(e, fname);
    }
    return statx_birthtime(&amp;st, fname);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-blockdev-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          blockdev?(filepath) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>filepath</code> points to a block device, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">blockdev?</span>(<span class="ruby-string">&#39;/dev/sda1&#39;</span>)       <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">blockdev?</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>)) <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="blockdev-3F-source">
            <pre>static VALUE
rb_file_blockdev_p(VALUE obj, VALUE fname)
{
#ifndef S_ISBLK
#   ifdef S_IFBLK
#       define S_ISBLK(m) (((m) &amp; S_IFMT) == S_IFBLK)
#   else
#       define S_ISBLK(m) (0)  /* anytime false */
#   endif
#endif

#ifdef S_ISBLK
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    if (S_ISBLK(st.st_mode)) return Qtrue;

#endif
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-chardev-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          chardev?(filepath) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>filepath</code> points to a character device, <code>false</code> otherwise.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">chardev?</span>(<span class="ruby-identifier">$stdin</span>)     <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">chardev?</span>(<span class="ruby-string">&#39;t.txt&#39;</span>)     <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="chardev-3F-source">
            <pre>static VALUE
rb_file_chardev_p(VALUE obj, VALUE fname)
{
#ifndef S_ISCHR
#   define S_ISCHR(m) (((m) &amp; S_IFMT) == S_IFCHR)
#endif

    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    if (S_ISCHR(st.st_mode)) return Qtrue;

    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-chmod" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          chmod(mode_int, file_name, ... )  &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Changes permission bits on the named file(s) to the bit pattern represented by <em>mode_int</em>. Actual effects are operating system dependent (see the beginning of this section). On Unix systems, see <code>chmod(2)</code> for details. Returns the number of files processed.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-value">0644</span>, <span class="ruby-string">&quot;testfile&quot;</span>, <span class="ruby-string">&quot;out&quot;</span>)   <span class="ruby-comment">#=&gt; 2</span>
</pre>

                              <div class="method-source-code" id="chmod-source">
            <pre>static VALUE
rb_file_s_chmod(int argc, VALUE *argv, VALUE _)
{
    mode_t mode;

    apply2args(1);
    mode = NUM2MODET(*argv++);

    return apply2files(chmod_internal, argc, argv, &amp;mode);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-chown" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          chown(owner_int, group_int, file_name, ...)  &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Changes the owner and group of the named file(s) to the given numeric owner and group id’s. Only a process with superuser privileges may change the owner of a file. The current owner of a file may change the file’s group to any group to which the owner belongs. A <code>nil</code> or -1 owner or group id is ignored. Returns the number of files processed.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">chown</span>(<span class="ruby-keyword">nil</span>, <span class="ruby-value">100</span>, <span class="ruby-string">&quot;testfile&quot;</span>)
</pre>

                              <div class="method-source-code" id="chown-source">
            <pre>static VALUE
rb_file_s_chown(int argc, VALUE *argv, VALUE _)
{
    struct chown_args arg;

    apply2args(2);
    arg.owner = to_uid(*argv++);
    arg.group = to_gid(*argv++);

    return apply2files(chown_internal, argc, argv, &amp;arg);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-ctime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ctime(file_name)  &rarr; time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the change time for the named file (the time at which directory information about the file was changed, not the file itself).</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<p>Note that on Windows (NTFS), returns creation time (birth time).</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">ctime</span>(<span class="ruby-string">&quot;testfile&quot;</span>)   <span class="ruby-comment">#=&gt; Wed Apr 09 08:53:13 CDT 2003</span>
</pre>

                              <div class="method-source-code" id="ctime-source">
            <pre>static VALUE
rb_file_s_ctime(VALUE klass, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) {
        int e = errno;
        FilePathValue(fname);
        rb_syserr_fail_path(e, fname);
    }
    return stat_ctime(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-delete" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete(file_name, ...)  &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          unlink(file_name, ...)  &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Deletes the named files, returning the number of names passed as arguments. Raises an exception on any error. Since the underlying implementation relies on the <code>unlink(2)</code> system call, the type of exception raised depends on its error type (see <a href="https://linux.die.net/man/2/unlink">linux.die.net/man/2/unlink</a>) and has the form of e.g. Errno::ENOENT.</p>

<p>See also <a href="Dir.html#method-c-rmdir"><code>Dir::rmdir</code></a>.</p>

                              <div class="method-source-code" id="delete-source">
            <pre>static VALUE
rb_file_s_unlink(int argc, VALUE *argv, VALUE klass)
{
    return apply2files(unlink_internal, argc, argv, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-directory-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          directory?(path) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>With string <code>object</code> given, returns <code>true</code> if <code>path</code> is a string path leading to a directory, or to a symbolic link to a directory; <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-string">&#39;.&#39;</span>)              <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-string">&#39;foo&#39;</span>)            <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&#39;.&#39;</span>, <span class="ruby-string">&#39;dirlink&#39;</span>)      <span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-string">&#39;dirlink&#39;</span>)        <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&#39;t,txt&#39;</span>, <span class="ruby-string">&#39;filelink&#39;</span>) <span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-string">&#39;filelink&#39;</span>)       <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>Argument <code>path</code> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="directory-3F-source">
            <pre>VALUE
rb_file_directory_p(VALUE obj, VALUE fname)
{
#ifndef S_ISDIR
#   define S_ISDIR(m) (((m) &amp; S_IFMT) == S_IFDIR)
#endif

    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    if (S_ISDIR(st.st_mode)) return Qtrue;
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-dirname" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dirname(file_name, level = 1)  &rarr;  dir_name
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns all components of the filename given in <em>file_name</em> except the last one (after first stripping trailing separators). The filename can be formed using both <a href="File.html#SEPARATOR"><code>File::SEPARATOR</code></a> and <a href="File.html#ALT_SEPARATOR"><code>File::ALT_SEPARATOR</code></a> as the separator when <a href="File.html#ALT_SEPARATOR"><code>File::ALT_SEPARATOR</code></a> is not <code>nil</code>.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-string">&quot;/home/gumby/work/ruby.rb&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;/home/gumby/work&quot;</span>
</pre>

<p>If <code>level</code> is given, removes the last <code>level</code> components, not only one.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-string">&quot;/home/gumby/work/ruby.rb&quot;</span>, <span class="ruby-value">2</span>) <span class="ruby-comment">#=&gt; &quot;/home/gumby&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-string">&quot;/home/gumby/work/ruby.rb&quot;</span>, <span class="ruby-value">4</span>) <span class="ruby-comment">#=&gt; &quot;/&quot;</span>
</pre>

                              <div class="method-source-code" id="dirname-source">
            <pre>static VALUE
rb_file_s_dirname(int argc, VALUE *argv, VALUE klass)
{
    int n = 1;
    if ((argc = rb_check_arity(argc, 1, 2)) &gt; 1) {
        n = NUM2INT(argv[1]);
    }
    return rb_file_dirname_n(argv[0], n);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-empty-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          zero?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file exists and has a zero size.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="empty-3F-source">
            <pre>static VALUE
rb_file_zero_p(VALUE obj, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    return RBOOL(st.st_size == 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-executable-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          executable?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file is executable by the effective user and group id of this process. See eaccess(3).</p>

<p>Windows does not support execute permissions separately from read permissions. On Windows, a file is only considered executable if it ends in .bat, .cmd, .com, or .exe.</p>

<p>Note that some OS-level security features may cause this to return true even though the file is not executable by the effective user/group.</p>

                              <div class="method-source-code" id="executable-3F-source">
            <pre>static VALUE
rb_file_executable_p(VALUE obj, VALUE fname)
{
    return RBOOL(rb_eaccess(fname, X_OK) &gt;= 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-executable_real-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          executable_real?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file is executable by the real user and group id of this process. See access(3).</p>

<p>Windows does not support execute permissions separately from read permissions. On Windows, a file is only considered executable if it ends in .bat, .cmd, .com, or .exe.</p>

<p>Note that some OS-level security features may cause this to return true even though the file is not executable by the real user/group.</p>

                              <div class="method-source-code" id="executable_real-3F-source">
            <pre>static VALUE
rb_file_executable_real_p(VALUE obj, VALUE fname)
{
    return RBOOL(rb_access(fname, X_OK) &gt;= 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-exist-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          exist?(file_name)    &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Return <code>true</code> if the named file exists.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<p>“file exists” means that stat() or fstat() system call is successful.</p>

                              <div class="method-source-code" id="exist-3F-source">
            <pre>static VALUE
rb_file_exist_p(VALUE obj, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    return Qtrue;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-expand_path" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          expand_path(file_name [, dir_string] )  &rarr;  abs_file_name
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Converts a pathname to an absolute pathname. Relative paths are referenced from the current working directory of the process unless <code>dir_string</code> is given, in which case it will be used as the starting point. The given pathname may start with a “<code>~</code>”, which expands to the process owner’s home directory (the environment variable <code>HOME</code> must be set correctly). “<code>~</code><em>user</em>” expands to the named user’s home directory.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;~oracle/bin&quot;</span>)           <span class="ruby-comment">#=&gt; &quot;/home/oracle/bin&quot;</span>
</pre>

<p>A simple example of using <code>dir_string</code> is as follows.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;ruby&quot;</span>, <span class="ruby-string">&quot;/usr/bin&quot;</span>)      <span class="ruby-comment">#=&gt; &quot;/usr/bin/ruby&quot;</span>
</pre>

<p>A more complex example which also resolves parent directory is as follows. Suppose we are in bin/mygem and want the absolute path of lib/mygem.rb.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&quot;../../lib/mygem.rb&quot;</span>, <span class="ruby-keyword">__FILE__</span>)
<span class="ruby-comment">#=&gt; &quot;.../path/to/project/lib/mygem.rb&quot;</span>
</pre>

<p>So first it resolves the parent of __FILE__, that is bin/, then go to the parent, the root of the project and appends <code>lib/mygem.rb</code>.</p>

                              <div class="method-source-code" id="expand_path-source">
            <pre>static VALUE
s_expand_path(int c, const VALUE * v, VALUE _)
{
    return rb_file_s_expand_path(c, v);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-extname" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          extname(path)  &rarr;  string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the extension (the portion of file name in <code>path</code> starting from the last period).</p>

<p>If <code>path</code> is a dotfile, or starts with a period, then the starting dot is not dealt with the start of the extension.</p>

<p>An empty string will also be returned when the period is the last character in <code>path</code>.</p>

<p>On Windows, trailing dots are truncated.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;test.rb&quot;</span>)         <span class="ruby-comment">#=&gt; &quot;.rb&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;a/b/d/test.rb&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;.rb&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;.a/b/d/test.rb&quot;</span>)  <span class="ruby-comment">#=&gt; &quot;.rb&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;foo.&quot;</span>)            <span class="ruby-comment">#=&gt; &quot;&quot; on Windows</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;foo.&quot;</span>)            <span class="ruby-comment">#=&gt; &quot;.&quot; on non-Windows</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;test&quot;</span>)            <span class="ruby-comment">#=&gt; &quot;&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;.profile&quot;</span>)        <span class="ruby-comment">#=&gt; &quot;&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-string">&quot;.profile.sh&quot;</span>)     <span class="ruby-comment">#=&gt; &quot;.sh&quot;</span>
</pre>

                              <div class="method-source-code" id="extname-source">
            <pre>static VALUE
rb_file_s_extname(VALUE klass, VALUE fname)
{
    const char *name, *e;
    long len;
    VALUE extname;

    FilePathStringValue(fname);
    name = StringValueCStr(fname);
    len = RSTRING_LEN(fname);
    e = ruby_enc_find_extname(name, &amp;len, rb_enc_get(fname));
    if (len &lt; 1)
        return rb_str_new(0, 0);
    extname = rb_str_subseq(fname, e - name, len); /* keep the dot, too! */
    return extname;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-file-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          file?(file) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named <code>file</code> exists and is a regular file.</p>

<p><code>file</code> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<p>If the <code>file</code> argument is a symbolic link, it will resolve the symbolic link and use the file referenced by the link.</p>

                              <div class="method-source-code" id="file-3F-source">
            <pre>static VALUE
rb_file_file_p(VALUE obj, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    return RBOOL(S_ISREG(st.st_mode));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-fnmatch" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          fnmatch( pattern, path, [flags] ) &rarr; (true or false)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if <code>path</code> matches against <code>pattern</code>.  The pattern is not a regular expression; instead it follows rules similar to shell filename globbing.  It may contain the following metacharacters:</p>
<dl class="rdoc-list note-list"><dt><code>*</code>
<dd>
<p>Matches any file. Can be restricted by other values in the glob. Equivalent to <code>/.*/x</code> in regexp.</p>
<dl class="rdoc-list note-list"><dt><code>*</code>
<dd>
<p>Matches all regular files</p>
</dd><dt><code>c*</code>
<dd>
<p>Matches all files beginning with <code>c</code></p>
</dd><dt><code>*c</code>
<dd>
<p>Matches all files ending with <code>c</code></p>
</dd><dt><code>*c*</code>
<dd>
<p>Matches all files that have <code>c</code> in them (including at the beginning or end).</p>
</dd></dl>

<p>To match hidden files (that start with a <code>.</code>) set the File::FNM_DOTMATCH flag.</p>
</dd><dt><code>**</code>
<dd>
<p>Matches directories recursively or files expansively.</p>
</dd><dt><code>?</code>
<dd>
<p>Matches any one character. Equivalent to <code>/.{1}/</code> in regexp.</p>
</dd><dt><code>[set]</code>
<dd>
<p>Matches any one character in <code>set</code>.  Behaves exactly like character sets in <a href="Regexp.html"><code>Regexp</code></a>, including set negation (<code>[^a-z]</code>).</p>
</dd><dt><code>\</code>
<dd>
<p>Escapes the next metacharacter.</p>
</dd><dt><code>{a,b}</code>
<dd>
<p>Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled. Behaves like a <a href="Regexp.html"><code>Regexp</code></a> union (<code>(?:a|b)</code>).</p>
</dd></dl>

<p><code>flags</code> is a bitwise OR of the <code>FNM_XXX</code> constants. The same glob pattern and flags are used by <a href="Dir.html#method-c-glob"><code>Dir::glob</code></a>.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;cat&#39;</span>,       <span class="ruby-string">&#39;cat&#39;</span>)        <span class="ruby-comment">#=&gt; true  # match entire string</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;cat&#39;</span>,       <span class="ruby-string">&#39;category&#39;</span>)   <span class="ruby-comment">#=&gt; false # only match partial string</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;c{at,ub}s&#39;</span>, <span class="ruby-string">&#39;cats&#39;</span>)                    <span class="ruby-comment">#=&gt; false # { } isn&#39;t supported by default</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;c{at,ub}s&#39;</span>, <span class="ruby-string">&#39;cats&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_EXTGLOB</span>) <span class="ruby-comment">#=&gt; true  # { } is supported on FNM_EXTGLOB</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;c?t&#39;</span>,     <span class="ruby-string">&#39;cat&#39;</span>)          <span class="ruby-comment">#=&gt; true  # &#39;?&#39; match only 1 character</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;c??t&#39;</span>,    <span class="ruby-string">&#39;cat&#39;</span>)          <span class="ruby-comment">#=&gt; false # ditto</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;c*&#39;</span>,      <span class="ruby-string">&#39;cats&#39;</span>)         <span class="ruby-comment">#=&gt; true  # &#39;*&#39; match 0 or more characters</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;c*t&#39;</span>,     <span class="ruby-string">&#39;c/a/b/t&#39;</span>)      <span class="ruby-comment">#=&gt; true  # ditto</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;ca[a-z]&#39;</span>, <span class="ruby-string">&#39;cat&#39;</span>)          <span class="ruby-comment">#=&gt; true  # inclusive bracket expression</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;ca[^t]&#39;</span>,  <span class="ruby-string">&#39;cat&#39;</span>)          <span class="ruby-comment">#=&gt; false # exclusive bracket expression (&#39;^&#39; or &#39;!&#39;)</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;cat&#39;</span>, <span class="ruby-string">&#39;CAT&#39;</span>)                     <span class="ruby-comment">#=&gt; false # case sensitive</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;cat&#39;</span>, <span class="ruby-string">&#39;CAT&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_CASEFOLD</span>) <span class="ruby-comment">#=&gt; true  # case insensitive</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;cat&#39;</span>, <span class="ruby-string">&#39;CAT&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_SYSCASE</span>)  <span class="ruby-comment">#=&gt; true or false # depends on the system default</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;?&#39;</span>,   <span class="ruby-string">&#39;/&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)  <span class="ruby-comment">#=&gt; false # wildcard doesn&#39;t match &#39;/&#39; on FNM_PATHNAME</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;*&#39;</span>,   <span class="ruby-string">&#39;/&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)  <span class="ruby-comment">#=&gt; false # ditto</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;[/]&#39;</span>, <span class="ruby-string">&#39;/&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)  <span class="ruby-comment">#=&gt; false # ditto</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;\?&#39;</span>,   <span class="ruby-string">&#39;?&#39;</span>)                       <span class="ruby-comment">#=&gt; true  # escaped wildcard becomes ordinary</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;\a&#39;</span>,   <span class="ruby-string">&#39;a&#39;</span>)                       <span class="ruby-comment">#=&gt; true  # escaped ordinary remains ordinary</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;\a&#39;</span>,   <span class="ruby-string">&#39;\a&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_NOESCAPE</span>)  <span class="ruby-comment">#=&gt; true  # FNM_NOESCAPE makes &#39;\&#39; ordinary</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;[\?]&#39;</span>, <span class="ruby-string">&#39;?&#39;</span>)                       <span class="ruby-comment">#=&gt; true  # can escape inside bracket expression</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;*&#39;</span>,   <span class="ruby-string">&#39;.profile&#39;</span>)                      <span class="ruby-comment">#=&gt; false # wildcard doesn&#39;t match leading</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;*&#39;</span>,   <span class="ruby-string">&#39;.profile&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_DOTMATCH</span>)  <span class="ruby-comment">#=&gt; true  # period by default.</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;.*&#39;</span>,  <span class="ruby-string">&#39;.profile&#39;</span>)                      <span class="ruby-comment">#=&gt; true</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/*.rb&#39;</span>, <span class="ruby-string">&#39;main.rb&#39;</span>)                  <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/*.rb&#39;</span>, <span class="ruby-string">&#39;./main.rb&#39;</span>)                <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/*.rb&#39;</span>, <span class="ruby-string">&#39;lib/song.rb&#39;</span>)              <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**.rb&#39;</span>, <span class="ruby-string">&#39;main.rb&#39;</span>)                    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**.rb&#39;</span>, <span class="ruby-string">&#39;./main.rb&#39;</span>)                  <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**.rb&#39;</span>, <span class="ruby-string">&#39;lib/song.rb&#39;</span>)                <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;*&#39;</span>,     <span class="ruby-string">&#39;dave/.profile&#39;</span>)              <span class="ruby-comment">#=&gt; true</span>

<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/foo&#39;</span>, <span class="ruby-string">&#39;a/b/c/foo&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)     <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/foo&#39;</span>, <span class="ruby-string">&#39;/a/b/c/foo&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/foo&#39;</span>, <span class="ruby-string">&#39;c:/a/b/c/foo&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)  <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/foo&#39;</span>, <span class="ruby-string">&#39;a/.b/c/foo&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span>)    <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">fnmatch</span>(<span class="ruby-string">&#39;**/foo&#39;</span>, <span class="ruby-string">&#39;a/.b/c/foo&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_PATHNAME</span> <span class="ruby-operator">|</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">FNM_DOTMATCH</span>) <span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="fnmatch-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/dir.rb, line 502</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fnmatch</span>(<span class="ruby-identifier">pattern</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">flags</span> = <span class="ruby-value">0</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="File.html#method-c-fnmatch-3F">fnmatch?</a>
                            </div>

                          </div>

                  <div id="method-c-fnmatch-3F" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">fnmatch?</span><span
                                class="method-args">(pattern, path, flags = 0)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="File.html#method-c-fnmatch">fnmatch</a>
                            </div>
                          </div>

                  <div id="method-c-ftype" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ftype(file_name)   &rarr; string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Identifies the type of the named file; the return string is one of “<code>file</code>”, “<code>directory</code>”, “<code>characterSpecial</code>”, “<code>blockSpecial</code>”, “<code>fifo</code>”, “<code>link</code>”, “<code>socket</code>”, or “<code>unknown</code>”.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">ftype</span>(<span class="ruby-string">&quot;testfile&quot;</span>)            <span class="ruby-comment">#=&gt; &quot;file&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">ftype</span>(<span class="ruby-string">&quot;/dev/tty&quot;</span>)            <span class="ruby-comment">#=&gt; &quot;characterSpecial&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">ftype</span>(<span class="ruby-string">&quot;/tmp/.X11-unix/X0&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;socket&quot;</span>
</pre>

                              <div class="method-source-code" id="ftype-source">
            <pre>static VALUE
rb_file_s_ftype(VALUE klass, VALUE fname)
{
    struct stat st;

    FilePathValue(fname);
    fname = rb_str_encode_ospath(fname);
    if (lstat_without_gvl(StringValueCStr(fname), &amp;st) == -1) {
        rb_sys_fail_path(fname);
    }

    return rb_file_ftype(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-grpowned-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          grpowned?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file exists and the effective group id of the calling process is the owner of the file. Returns <code>false</code> on Windows.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="grpowned-3F-source">
            <pre>static VALUE
rb_file_grpowned_p(VALUE obj, VALUE fname)
{
#ifndef _WIN32
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    if (rb_group_member(st.st_gid)) return Qtrue;
#endif
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-identical-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          identical?(file_1, file_2)   &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named files are identical.</p>

<p><em>file_1</em> and <em>file_2</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<pre class="ruby"><span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;w&quot;</span>) {}
<span class="ruby-identifier">p</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">identical?</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;a&quot;</span>)      <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">p</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">identical?</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;./a&quot;</span>)    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">link</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;b&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">identical?</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;b&quot;</span>)      <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;c&quot;</span>)
<span class="ruby-identifier">p</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">identical?</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;c&quot;</span>)      <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;d&quot;</span>, <span class="ruby-string">&quot;w&quot;</span>) {}
<span class="ruby-identifier">p</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">identical?</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;d&quot;</span>)      <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="identical-3F-source">
            <pre>static VALUE
rb_file_identical_p(VALUE obj, VALUE fname1, VALUE fname2)
{
#ifndef _WIN32
    struct stat st1, st2;

    if (rb_stat(fname1, &amp;st1) &lt; 0) return Qfalse;
    if (rb_stat(fname2, &amp;st2) &lt; 0) return Qfalse;
    if (st1.st_dev != st2.st_dev) return Qfalse;
    if (st1.st_ino != st2.st_ino) return Qfalse;
    return Qtrue;
#else
    extern VALUE rb_w32_file_identical_p(VALUE, VALUE);
    return rb_w32_file_identical_p(fname1, fname2);
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-join" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          join(string, ...)  &rarr;  string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new string formed by joining the strings using <code>&quot;/&quot;</code>.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;usr&quot;</span>, <span class="ruby-string">&quot;mail&quot;</span>, <span class="ruby-string">&quot;gumby&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;usr/mail/gumby&quot;</span>
</pre>

                              <div class="method-source-code" id="join-source">
            <pre>static VALUE
rb_file_s_join(VALUE klass, VALUE args)
{
    return rb_file_join(args);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-lchmod" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lchmod(mode_int, file_name, ...)  &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equivalent to <a href="File.html#method-c-chmod"><code>File::chmod</code></a>, but does not follow symbolic links (so it will change the permissions associated with the link, not the file referenced by the link). Often not available.</p>

                              <div class="method-source-code" id="lchmod-source">
            <pre>static VALUE
rb_file_s_lchmod(int argc, VALUE *argv, VALUE _)
{
    mode_t mode;

    apply2args(1);
    mode = NUM2MODET(*argv++);

    return apply2files(lchmod_internal, argc, argv, &amp;mode);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-lchown" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lchown(owner_int, group_int, file_name,..) &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Equivalent to <a href="File.html#method-c-chown"><code>File::chown</code></a>, but does not follow symbolic links (so it will change the owner associated with the link, not the file referenced by the link). Often not available. Returns number of files in the argument list.</p>

                              <div class="method-source-code" id="lchown-source">
            <pre>static VALUE
rb_file_s_lchown(int argc, VALUE *argv, VALUE _)
{
    struct chown_args arg;

    apply2args(2);
    arg.owner = to_uid(*argv++);
    arg.group = to_gid(*argv++);

    return apply2files(lchown_internal, argc, argv, &amp;arg);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-link" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          link(old_name, new_name)    &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new name for an existing file using a hard link. Will not overwrite <em>new_name</em> if it already exists (raising a subclass of <a href="SystemCallError.html"><code>SystemCallError</code></a>). Not available on all platforms.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">link</span>(<span class="ruby-string">&quot;testfile&quot;</span>, <span class="ruby-string">&quot;.testfile&quot;</span>)   <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">IO</span>.<span class="ruby-identifier">readlines</span>(<span class="ruby-string">&quot;.testfile&quot;</span>)[<span class="ruby-value">0</span>]         <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
</pre>

                              <div class="method-source-code" id="link-source">
            <pre>static VALUE
rb_file_s_link(VALUE klass, VALUE from, VALUE to)
{
    FilePathValue(from);
    FilePathValue(to);
    from = rb_str_encode_ospath(from);
    to = rb_str_encode_ospath(to);

    if (link(StringValueCStr(from), StringValueCStr(to)) &lt; 0) {
        sys_fail2(from, to);
    }
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-lstat" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lstat(filepath) &rarr; stat
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Like <a href="File.html#method-c-stat"><code>File::stat</code></a>, but does not follow the last symbolic link; instead, returns a <a href="File/Stat.html"><code>File::Stat</code></a> object for the link itself.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&#39;t.txt&#39;</span>, <span class="ruby-string">&#39;symlink&#39;</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">&#39;symlink&#39;</span>).<span class="ruby-identifier">size</span>  <span class="ruby-comment"># =&gt; 47</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">lstat</span>(<span class="ruby-string">&#39;symlink&#39;</span>).<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 5</span>
</pre>

                              <div class="method-source-code" id="lstat-source">
            <pre>static VALUE
rb_file_s_lstat(VALUE klass, VALUE fname)
{
#ifdef HAVE_LSTAT
    struct stat st;

    FilePathValue(fname);
    fname = rb_str_encode_ospath(fname);
    if (lstat_without_gvl(StringValueCStr(fname), &amp;st) == -1) {
        rb_sys_fail_path(fname);
    }
    return rb_stat_new(&amp;st);
#else
    return rb_file_s_stat(klass, fname);
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-lutime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lutime(atime, mtime, file_name, ...)   &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the access and modification times of each named file to the first two arguments. If a file is a symlink, this method acts upon the link itself as opposed to its referent; for the inverse behavior, see <a href="File.html#method-c-utime"><code>File.utime</code></a>. Returns the number of file names in the argument list.</p>

                              <div class="method-source-code" id="lutime-source">
            <pre>static VALUE
rb_file_s_lutime(int argc, VALUE *argv, VALUE _)
{
    return utime_internal_i(argc, argv, TRUE);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-mkfifo" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mkfifo(file_name, mode=0666)  &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a FIFO special file with name <em>file_name</em>.  <em>mode</em> specifies the FIFO’s permissions. It is modified by the process’s umask in the usual way: the permissions of the created file are (mode &amp; ~umask).</p>

                              <div class="method-source-code" id="mkfifo-source">
            <pre>static VALUE
rb_file_s_mkfifo(int argc, VALUE *argv, VALUE _)
{
    VALUE path;
    struct mkfifo_arg ma;

    ma.mode = 0666;
    rb_check_arity(argc, 1, 2);
    if (argc &gt; 1) {
        ma.mode = NUM2MODET(argv[1]);
    }
    path = argv[0];
    FilePathValue(path);
    path = rb_str_encode_ospath(path);
    ma.path = RSTRING_PTR(path);
    if (rb_thread_call_without_gvl(nogvl_mkfifo, &amp;ma, RUBY_UBF_IO, 0)) {
        rb_sys_fail_path(path);
    }
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-mtime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mtime(file_name)  &rarr;  time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the modification time for the named file as a <a href="Time.html"><code>Time</code></a> object.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">mtime</span>(<span class="ruby-string">&quot;testfile&quot;</span>)   <span class="ruby-comment">#=&gt; Tue Apr 08 12:58:04 CDT 2003</span>
</pre>

                              <div class="method-source-code" id="mtime-source">
            <pre>static VALUE
rb_file_s_mtime(VALUE klass, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) {
        int e = errno;
        FilePathValue(fname);
        rb_syserr_fail_path(e, fname);
    }
    return stat_mtime(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(path, mode = &#39;r&#39;, perm = 0666, **opts) &rarr; file
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Opens the file at the given <code>path</code> according to the given <code>mode</code>; creates and returns a new <a href="File.html"><code>File</code></a> object for that file.</p>

<p>The new <a href="File.html"><code>File</code></a> object is buffered mode (or non-sync mode), unless <code>filename</code> is a tty. See <a href="IO.html#method-i-flush"><code>IO#flush</code></a>, <a href="IO.html#method-i-fsync"><code>IO#fsync</code></a>, <a href="IO.html#method-i-fdatasync"><code>IO#fdatasync</code></a>, and <a href="IO.html#method-i-sync-3D"><code>IO#sync=</code></a>.</p>

<p>Argument <code>path</code> must be a valid file path:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;/etc/fstab&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.txt&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
</pre>

<p>Optional argument <code>mode</code> (defaults to ‘r’) must specify a valid mode; see <a href="File.html#class-File-label-Access+Modes">Access Modes</a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-string">&#39;w&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">RDONLY</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
</pre>

<p>Optional argument <code>perm</code> (defaults to 0666) must specify valid permissions see <a href="File.html#class-File-label-File+Permissions">File Permissions</a>:</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span>, <span class="ruby-value">0644</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.tmp&#39;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span>, <span class="ruby-value">0444</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>
</pre>

<p>Optional keyword arguments <code>opts</code> specify:</p>
<ul><li>
<p><a href="IO.html#class-IO-label-Open+Options">Open Options</a>.</p>
</li><li>
<p><a href="encodings_rdoc.html#label-Encoding+Options">Encoding options</a>.</p>
</li></ul>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
rb_file_initialize(int argc, VALUE *argv, VALUE io)
{
    if (RFILE(io)-&gt;fptr) {
        rb_raise(rb_eRuntimeError, &quot;reinitializing File&quot;);
    }
    if (0 &lt; argc &amp;&amp; argc &lt; 3) {
        VALUE fd = rb_check_to_int(argv[0]);

        if (!NIL_P(fd)) {
            argv[0] = fd;
            return rb_io_initialize(argc, argv, io);
        }
    }
    rb_open_file(argc, argv, io);

    return io;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-open" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          open(path, mode = &#39;r&#39;, perm = 0666, **opts) &rarr; file
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          open(path, mode = &#39;r&#39;, perm = 0666, **opts) {|f| ... } &rarr; object
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="File.html"><code>File</code></a> object, via <a href="File.html#method-c-new"><code>File.new</code></a> with the given arguments.</p>

<p>With no block given, returns the <a href="File.html"><code>File</code></a> object.</p>

<p>With a block given, calls the block with the <a href="File.html"><code>File</code></a> object and returns the block’s value.</p>

                              <div class="method-source-code" id="open-source">
            <pre>static VALUE
rb_io_s_open(int argc, VALUE *argv, VALUE klass)
{
    VALUE io = rb_class_new_instance_kw(argc, argv, klass, RB_PASS_CALLED_KEYWORDS);

    if (rb_block_given_p()) {
        return rb_ensure(rb_yield, io, io_close, io);
    }

    return io;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-owned-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          owned?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file exists and the effective used id of the calling process is the owner of the file.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="owned-3F-source">
            <pre>static VALUE
rb_file_owned_p(VALUE obj, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    return RBOOL(st.st_uid == geteuid());
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-path" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          path(path)  &rarr;  string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the string representation of the path</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">path</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">NULL</span>)           <span class="ruby-comment">#=&gt; &quot;/dev/null&quot;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">path</span>(<span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp&quot;</span>)) <span class="ruby-comment">#=&gt; &quot;/tmp&quot;</span>
</pre>

                              <div class="method-source-code" id="path-source">
            <pre>static VALUE
rb_file_s_path(VALUE klass, VALUE fname)
{
    return rb_get_path(fname);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-pipe-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          pipe?(filepath) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>filepath</code> points to a pipe, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">mkfifo</span>(<span class="ruby-string">&#39;tmp/fifo&#39;</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">pipe?</span>(<span class="ruby-string">&#39;tmp/fifo&#39;</span>) <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">pipe?</span>(<span class="ruby-string">&#39;t.txt&#39;</span>)    <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="pipe-3F-source">
            <pre>static VALUE
rb_file_pipe_p(VALUE obj, VALUE fname)
{
#ifdef S_IFIFO
#  ifndef S_ISFIFO
#    define S_ISFIFO(m) (((m) &amp; S_IFMT) == S_IFIFO)
#  endif

    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    if (S_ISFIFO(st.st_mode)) return Qtrue;

#endif
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-readable-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          readable?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file is readable by the effective user and group id of this process. See eaccess(3).</p>

<p>Note that some OS-level security features may cause this to return true even though the file is not readable by the effective user/group.</p>

                              <div class="method-source-code" id="readable-3F-source">
            <pre>static VALUE
rb_file_readable_p(VALUE obj, VALUE fname)
{
    return RBOOL(rb_eaccess(fname, R_OK) &gt;= 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-readable_real-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          readable_real?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file is readable by the real user and group id of this process. See access(3).</p>

<p>Note that some OS-level security features may cause this to return true even though the file is not readable by the real user/group.</p>

                              <div class="method-source-code" id="readable_real-3F-source">
            <pre>static VALUE
rb_file_readable_real_p(VALUE obj, VALUE fname)
{
    return RBOOL(rb_access(fname, R_OK) &gt;= 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-readlink" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          readlink(link_name)  &rarr;  file_name
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the name of the file referenced by the given link. Not available on all platforms.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&quot;testfile&quot;</span>, <span class="ruby-string">&quot;link2test&quot;</span>)   <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">readlink</span>(<span class="ruby-string">&quot;link2test&quot;</span>)              <span class="ruby-comment">#=&gt; &quot;testfile&quot;</span>
</pre>

                              <div class="method-source-code" id="readlink-source">
            <pre>static VALUE
rb_file_s_readlink(VALUE klass, VALUE path)
{
    return rb_readlink(path, rb_filesystem_encoding());
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-realdirpath" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          realdirpath(pathname [, dir_string])  &rarr;  real_pathname
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the real (absolute) pathname of <em>pathname</em> in the actual filesystem. The real pathname doesn’t contain symlinks or useless dots.</p>

<p>If <em>dir_string</em> is given, it is used as a base directory for interpreting relative pathname instead of the current directory.</p>

<p>The last component of the real pathname can be nonexistent.</p>

                              <div class="method-source-code" id="realdirpath-source">
            <pre>static VALUE
rb_file_s_realdirpath(int argc, VALUE *argv, VALUE klass)
{
    VALUE basedir = (rb_check_arity(argc, 1, 2) &gt; 1) ? argv[1] : Qnil;
    VALUE path = argv[0];
    FilePathValue(path);
    return rb_realpath_internal(basedir, path, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-realpath" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          realpath(pathname [, dir_string])  &rarr;  real_pathname
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the real (absolute) pathname of <em>pathname</em> in the actual filesystem not containing symlinks or useless dots.</p>

<p>If <em>dir_string</em> is given, it is used as a base directory for interpreting relative pathname instead of the current directory.</p>

<p>All components of the pathname must exist when this method is called.</p>

                              <div class="method-source-code" id="realpath-source">
            <pre>static VALUE
rb_file_s_realpath(int argc, VALUE *argv, VALUE klass)
{
    VALUE basedir = (rb_check_arity(argc, 1, 2) &gt; 1) ? argv[1] : Qnil;
    VALUE path = argv[0];
    FilePathValue(path);
    return rb_realpath_internal(basedir, path, 1);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-rename" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rename(old_name, new_name)   &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Renames the given file to the new name. Raises a <a href="SystemCallError.html"><code>SystemCallError</code></a> if the file cannot be renamed.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">rename</span>(<span class="ruby-string">&quot;afile&quot;</span>, <span class="ruby-string">&quot;afile.bak&quot;</span>)   <span class="ruby-comment">#=&gt; 0</span>
</pre>

                              <div class="method-source-code" id="rename-source">
            <pre>static VALUE
rb_file_s_rename(VALUE klass, VALUE from, VALUE to)
{
    struct rename_args ra;
    VALUE f, t;

    FilePathValue(from);
    FilePathValue(to);
    f = rb_str_encode_ospath(from);
    t = rb_str_encode_ospath(to);
    ra.src = StringValueCStr(f);
    ra.dst = StringValueCStr(t);
#if defined __CYGWIN__
    errno = 0;
#endif
    if ((int)(VALUE)rb_thread_call_without_gvl(no_gvl_rename, &amp;ra,
                                         RUBY_UBF_IO, 0) &lt; 0) {
        int e = errno;
#if defined DOSISH
        switch (e) {
          case EEXIST:
            if (chmod(ra.dst, 0666) == 0 &amp;&amp;
                unlink(ra.dst) == 0 &amp;&amp;
                rename(ra.src, ra.dst) == 0)
                return INT2FIX(0);
        }
#endif
        syserr_fail2(e, from, to);
    }

    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-setgid-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          setgid?(file_name)   &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file has the setgid bit set.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="setgid-3F-source">
            <pre>static VALUE
rb_file_sgid_p(VALUE obj, VALUE fname)
{
#ifdef S_ISGID
    return check3rdbyte(fname, S_ISGID);
#else
    return Qfalse;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-setuid-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          setuid?(file_name)   &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file has the setuid bit set.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="setuid-3F-source">
            <pre>static VALUE
rb_file_suid_p(VALUE obj, VALUE fname)
{
#ifdef S_ISUID
    return check3rdbyte(fname, S_ISUID);
#else
    return Qfalse;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-size" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size(file_name)   &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the size of <code>file_name</code>.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="size-source">
            <pre>static VALUE
rb_file_s_size(VALUE klass, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) {
        int e = errno;
        FilePathValue(fname);
        rb_syserr_fail_path(e, fname);
    }
    return OFFT2NUM(st.st_size);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-size-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          size?(file_name)   &rarr; Integer or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>nil</code> if <code>file_name</code> doesn’t exist or has zero size, the size of the file otherwise.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="size-3F-source">
            <pre>static VALUE
rb_file_size_p(VALUE obj, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qnil;
    if (st.st_size == 0) return Qnil;
    return OFFT2NUM(st.st_size);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-socket-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          socket?(filepath)   &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>filepath</code> points to a socket, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;socket&#39;</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">socket?</span>(<span class="ruby-constant">Socket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:INET</span>, <span class="ruby-value">:STREAM</span>)) <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">socket?</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;t.txt&#39;</span>))          <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="socket-3F-source">
            <pre>static VALUE
rb_file_socket_p(VALUE obj, VALUE fname)
{
#ifndef S_ISSOCK
#  ifdef _S_ISSOCK
#    define S_ISSOCK(m) _S_ISSOCK(m)
#  else
#    ifdef _S_IFSOCK
#      define S_ISSOCK(m) (((m) &amp; S_IFMT) == _S_IFSOCK)
#    else
#      ifdef S_IFSOCK
#        define S_ISSOCK(m) (((m) &amp; S_IFMT) == S_IFSOCK)
#      endif
#    endif
#  endif
#endif

#ifdef S_ISSOCK
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    if (S_ISSOCK(st.st_mode)) return Qtrue;
#endif

    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-split" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          split(file_name)   &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Splits the given string into a directory and a file component and returns them in a two-element array. See also <a href="File.html#method-c-dirname"><code>File::dirname</code></a> and <a href="File.html#method-c-basename"><code>File::basename</code></a>.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;/home/gumby/.profile&quot;</span>)   <span class="ruby-comment">#=&gt; [&quot;/home/gumby&quot;, &quot;.profile&quot;]</span>
</pre>

                              <div class="method-source-code" id="split-source">
            <pre>static VALUE
rb_file_s_split(VALUE klass, VALUE path)
{
    FilePathStringValue(path);          /* get rid of converting twice */
    return rb_assoc_new(rb_file_dirname(path), rb_file_s_basename(1,&amp;path,Qundef));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-stat" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          stat(filepath) &rarr;  stat
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a <a href="File/Stat.html"><code>File::Stat</code></a> object for the file at <code>filepath</code> (see <a href="File/Stat.html"><code>File::Stat</code></a>):</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-string">&#39;t.txt&#39;</span>).<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; File::Stat</span>
</pre>

                              <div class="method-source-code" id="stat-source">
            <pre>static VALUE
rb_file_s_stat(VALUE klass, VALUE fname)
{
    struct stat st;

    FilePathValue(fname);
    fname = rb_str_encode_ospath(fname);
    if (stat_without_gvl(RSTRING_PTR(fname), &amp;st) &lt; 0) {
        rb_sys_fail_path(fname);
    }
    return rb_stat_new(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-sticky-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sticky?(file_name)   &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file has the sticky bit set.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="sticky-3F-source">
            <pre>static VALUE
rb_file_sticky_p(VALUE obj, VALUE fname)
{
#ifdef S_ISVTX
    return check3rdbyte(fname, S_ISVTX);
#else
    return Qfalse;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-symlink" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          symlink(old_name, new_name)   &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a symbolic link called <em>new_name</em> for the existing file <em>old_name</em>. Raises a NotImplemented exception on platforms that do not support symbolic links.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&quot;testfile&quot;</span>, <span class="ruby-string">&quot;link2test&quot;</span>)   <span class="ruby-comment">#=&gt; 0</span>
</pre>

                              <div class="method-source-code" id="symlink-source">
            <pre>static VALUE
rb_file_s_symlink(VALUE klass, VALUE from, VALUE to)
{
    FilePathValue(from);
    FilePathValue(to);
    from = rb_str_encode_ospath(from);
    to = rb_str_encode_ospath(to);

    if (symlink(StringValueCStr(from), StringValueCStr(to)) &lt; 0) {
        sys_fail2(from, to);
    }
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-symlink-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          symlink?(filepath) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>filepath</code> points to a symbolic link, <code>false</code> otherwise:</p>

<pre class="ruby"><span class="ruby-identifier">symlink</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&#39;t.txt&#39;</span>, <span class="ruby-string">&#39;symlink&#39;</span>)
<span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink?</span>(<span class="ruby-string">&#39;symlink&#39;</span>) <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink?</span>(<span class="ruby-string">&#39;t.txt&#39;</span>)   <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="symlink-3F-source">
            <pre>static VALUE
rb_file_symlink_p(VALUE obj, VALUE fname)
{
#ifndef S_ISLNK
#  ifdef _S_ISLNK
#    define S_ISLNK(m) _S_ISLNK(m)
#  else
#    ifdef _S_IFLNK
#      define S_ISLNK(m) (((m) &amp; S_IFMT) == _S_IFLNK)
#    else
#      ifdef S_IFLNK
#        define S_ISLNK(m) (((m) &amp; S_IFMT) == S_IFLNK)
#      endif
#    endif
#  endif
#endif

#ifdef S_ISLNK
    struct stat st;

    FilePathValue(fname);
    fname = rb_str_encode_ospath(fname);
    if (lstat_without_gvl(StringValueCStr(fname), &amp;st) &lt; 0) return Qfalse;
    if (S_ISLNK(st.st_mode)) return Qtrue;
#endif

    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-truncate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          truncate(file_name, integer)  &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Truncates the file <em>file_name</em> to be at most <em>integer</em> bytes long. Not available on all platforms.</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;out&quot;</span>, <span class="ruby-string">&quot;w&quot;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&quot;1234567890&quot;</span>)     <span class="ruby-comment">#=&gt; 10</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>                   <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">truncate</span>(<span class="ruby-string">&quot;out&quot;</span>, <span class="ruby-value">5</span>)   <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">&quot;out&quot;</span>)          <span class="ruby-comment">#=&gt; 5</span>
</pre>

                              <div class="method-source-code" id="truncate-source">
            <pre>static VALUE
rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
{
    struct truncate_arg ta;
    int r;

    ta.pos = NUM2OFFT(len);
    FilePathValue(path);
    path = rb_str_encode_ospath(path);
    ta.path = StringValueCStr(path);

    r = (int)(VALUE)rb_thread_call_without_gvl(nogvl_truncate, &amp;ta,
                                                RUBY_UBF_IO, NULL);
    if (r &lt; 0)
        rb_sys_fail_path(path);
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-umask" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          umask()          &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          umask(integer)   &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the current umask value for this process. If the optional argument is given, set the umask to that value and return the previous value. Umask values are <em>subtracted</em> from the default permissions, so a umask of <code>0222</code> would make a file read-only for everyone.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span>(<span class="ruby-value">0006</span>)   <span class="ruby-comment">#=&gt; 18</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">umask</span>         <span class="ruby-comment">#=&gt; 6</span>
</pre>

                              <div class="method-source-code" id="umask-source">
            <pre>static VALUE
rb_file_s_umask(int argc, VALUE *argv, VALUE _)
{
    mode_t omask = 0;

    switch (argc) {
      case 0:
        omask = umask(0);
        umask(omask);
        break;
      case 1:
        omask = umask(NUM2MODET(argv[0]));
        break;
      default:
        rb_error_arity(argc, 0, 1);
    }
    return MODET2NUM(omask);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-unlink" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          delete(file_name, ...)  &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          unlink(file_name, ...)  &rarr; integer
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Deletes the named files, returning the number of names passed as arguments. Raises an exception on any error. Since the underlying implementation relies on the <code>unlink(2)</code> system call, the type of exception raised depends on its error type (see <a href="https://linux.die.net/man/2/unlink">linux.die.net/man/2/unlink</a>) and has the form of e.g. Errno::ENOENT.</p>

<p>See also <a href="Dir.html#method-c-rmdir"><code>Dir::rmdir</code></a>.</p>

                              <div class="method-source-code" id="unlink-source">
            <pre>static VALUE
rb_file_s_unlink(int argc, VALUE *argv, VALUE klass)
{
    return apply2files(unlink_internal, argc, argv, 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-utime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          utime(atime, mtime, file_name, ...)   &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the access and modification times of each named file to the first two arguments. If a file is a symlink, this method acts upon its referent rather than the link itself; for the inverse behavior see <a href="File.html#method-c-lutime"><code>File.lutime</code></a>. Returns the number of file names in the argument list.</p>

                              <div class="method-source-code" id="utime-source">
            <pre>static VALUE
rb_file_s_utime(int argc, VALUE *argv, VALUE _)
{
    return utime_internal_i(argc, argv, FALSE);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-world_readable-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          world_readable?(file_name)   &rarr; integer or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>If <em>file_name</em> is readable by others, returns an integer representing the file permission bits of <em>file_name</em>. Returns <code>nil</code> otherwise. The meaning of the bits is platform dependent; on Unix systems, see <code>stat(2)</code>.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">world_readable?</span>(<span class="ruby-string">&quot;/etc/passwd&quot;</span>)           <span class="ruby-comment">#=&gt; 420</span>
<span class="ruby-identifier">m</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">world_readable?</span>(<span class="ruby-string">&quot;/etc/passwd&quot;</span>)
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;%o&quot;</span>, <span class="ruby-identifier">m</span>)                              <span class="ruby-comment">#=&gt; &quot;644&quot;</span>
</pre>

                              <div class="method-source-code" id="world_readable-3F-source">
            <pre>static VALUE
rb_file_world_readable_p(VALUE obj, VALUE fname)
{
#ifdef S_IROTH
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qnil;
    if ((st.st_mode &amp; (S_IROTH)) == S_IROTH) {
        return UINT2NUM(st.st_mode &amp; (S_IRUGO|S_IWUGO|S_IXUGO));
    }
#endif
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-world_writable-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          world_writable?(file_name)   &rarr; integer or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>If <em>file_name</em> is writable by others, returns an integer representing the file permission bits of <em>file_name</em>. Returns <code>nil</code> otherwise. The meaning of the bits is platform dependent; on Unix systems, see <code>stat(2)</code>.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">world_writable?</span>(<span class="ruby-string">&quot;/tmp&quot;</span>)                  <span class="ruby-comment">#=&gt; 511</span>
<span class="ruby-identifier">m</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">world_writable?</span>(<span class="ruby-string">&quot;/tmp&quot;</span>)
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;%o&quot;</span>, <span class="ruby-identifier">m</span>)                              <span class="ruby-comment">#=&gt; &quot;777&quot;</span>
</pre>

                              <div class="method-source-code" id="world_writable-3F-source">
            <pre>static VALUE
rb_file_world_writable_p(VALUE obj, VALUE fname)
{
#ifdef S_IWOTH
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qnil;
    if ((st.st_mode &amp; (S_IWOTH)) == S_IWOTH) {
        return UINT2NUM(st.st_mode &amp; (S_IRUGO|S_IWUGO|S_IXUGO));
    }
#endif
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-writable-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          writable?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file is writable by the effective user and group id of this process. See eaccess(3).</p>

<p>Note that some OS-level security features may cause this to return true even though the file is not writable by the effective user/group.</p>

                              <div class="method-source-code" id="writable-3F-source">
            <pre>static VALUE
rb_file_writable_p(VALUE obj, VALUE fname)
{
    return RBOOL(rb_eaccess(fname, W_OK) &gt;= 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-writable_real-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          writable_real?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file is writable by the real user and group id of this process. See access(3).</p>

<p>Note that some OS-level security features may cause this to return true even though the file is not writable by the real user/group.</p>

                              <div class="method-source-code" id="writable_real-3F-source">
            <pre>static VALUE
rb_file_writable_real_p(VALUE obj, VALUE fname)
{
    return RBOOL(rb_access(fname, W_OK) &gt;= 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-zero-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          zero?(file_name)   &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if the named file exists and has a zero size.</p>

<p><em>file_name</em> can be an <a href="IO.html"><code>IO</code></a> object.</p>

                              <div class="method-source-code" id="zero-3F-source">
            <pre>static VALUE
rb_file_zero_p(VALUE obj, VALUE fname)
{
    struct stat st;

    if (rb_stat(fname, &amp;st) &lt; 0) return Qfalse;
    return RBOOL(st.st_size == 0);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-atime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          atime    &rarr; time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the last access time (a <a href="Time.html"><code>Time</code></a> object) for <em>file</em>, or epoch if <em>file</em> has not been accessed.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;testfile&quot;</span>).<span class="ruby-identifier">atime</span>   <span class="ruby-comment">#=&gt; Wed Dec 31 18:00:00 CST 1969</span>
</pre>

                              <div class="method-source-code" id="atime-source">
            <pre>static VALUE
rb_file_atime(VALUE obj)
{
    rb_io_t *fptr;
    struct stat st;

    GetOpenFile(obj, fptr);
    if (fstat(fptr-&gt;fd, &amp;st) == -1) {
        rb_sys_fail_path(fptr-&gt;pathv);
    }
    return stat_atime(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-birthtime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          birthtime  &rarr;  time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the birth time for <em>file</em>.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;testfile&quot;</span>).<span class="ruby-identifier">birthtime</span>   <span class="ruby-comment">#=&gt; Wed Apr 09 08:53:14 CDT 2003</span>
</pre>

<p>If the platform doesn’t have birthtime, raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a>.</p>

                              <div class="method-source-code" id="birthtime-source">
            <pre>static VALUE
rb_file_birthtime(VALUE obj)
{
    rb_io_t *fptr;
    statx_data st;

    GetOpenFile(obj, fptr);
    if (fstatx_without_gvl(fptr-&gt;fd, &amp;st, STATX_BTIME) == -1) {
        rb_sys_fail_path(fptr-&gt;pathv);
    }
    return statx_birthtime(&amp;st, fptr-&gt;pathv);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-chmod" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          chmod(mode_int)   &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Changes permission bits on <em>file</em> to the bit pattern represented by <em>mode_int</em>. Actual effects are platform dependent; on Unix systems, see <code>chmod(2)</code> for details. Follows symbolic links. Also see File#lchmod.</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;out&quot;</span>, <span class="ruby-string">&quot;w&quot;</span>);
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">chmod</span>(<span class="ruby-value">0644</span>)   <span class="ruby-comment">#=&gt; 0</span>
</pre>

                              <div class="method-source-code" id="chmod-source">
            <pre>static VALUE
rb_file_chmod(VALUE obj, VALUE vmode)
{
    rb_io_t *fptr;
    mode_t mode;
#if !defined HAVE_FCHMOD || !HAVE_FCHMOD
    VALUE path;
#endif

    mode = NUM2MODET(vmode);

    GetOpenFile(obj, fptr);
#ifdef HAVE_FCHMOD
    if (fchmod(fptr-&gt;fd, mode) == -1) {
        if (HAVE_FCHMOD || errno != ENOSYS)
            rb_sys_fail_path(fptr-&gt;pathv);
    }
    else {
        if (!HAVE_FCHMOD) return INT2FIX(0);
    }
#endif
#if !defined HAVE_FCHMOD || !HAVE_FCHMOD
    if (NIL_P(fptr-&gt;pathv)) return Qnil;
    path = rb_str_encode_ospath(fptr-&gt;pathv);
    if (chmod(RSTRING_PTR(path), mode) == -1)
        rb_sys_fail_path(fptr-&gt;pathv);
#endif

    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-chown" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          chown(owner_int, group_int )   &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Changes the owner and group of <em>file</em> to the given numeric owner and group id’s. Only a process with superuser privileges may change the owner of a file. The current owner of a file may change the file’s group to any group to which the owner belongs. A <code>nil</code> or -1 owner or group id is ignored. Follows symbolic links. See also File#lchown.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;testfile&quot;</span>).<span class="ruby-identifier">chown</span>(<span class="ruby-value">502</span>, <span class="ruby-value">1000</span>)
</pre>

                              <div class="method-source-code" id="chown-source">
            <pre>static VALUE
rb_file_chown(VALUE obj, VALUE owner, VALUE group)
{
    rb_io_t *fptr;
    rb_uid_t o;
    rb_gid_t g;
#ifndef HAVE_FCHOWN
    VALUE path;
#endif

    o = to_uid(owner);
    g = to_gid(group);
    GetOpenFile(obj, fptr);
#ifndef HAVE_FCHOWN
    if (NIL_P(fptr-&gt;pathv)) return Qnil;
    path = rb_str_encode_ospath(fptr-&gt;pathv);
    if (chown(RSTRING_PTR(path), o, g) == -1)
        rb_sys_fail_path(fptr-&gt;pathv);
#else
    if (fchown(fptr-&gt;fd, o, g) == -1)
        rb_sys_fail_path(fptr-&gt;pathv);
#endif

    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-ctime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ctime  &rarr;  time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the change time for <em>file</em> (that is, the time directory information about the file was changed, not the file itself).</p>

<p>Note that on Windows (NTFS), returns creation time (birth time).</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;testfile&quot;</span>).<span class="ruby-identifier">ctime</span>   <span class="ruby-comment">#=&gt; Wed Apr 09 08:53:14 CDT 2003</span>
</pre>

                              <div class="method-source-code" id="ctime-source">
            <pre>static VALUE
rb_file_ctime(VALUE obj)
{
    rb_io_t *fptr;
    struct stat st;

    GetOpenFile(obj, fptr);
    if (fstat(fptr-&gt;fd, &amp;st) == -1) {
        rb_sys_fail_path(fptr-&gt;pathv);
    }
    return stat_ctime(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-flock" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          flock(locking_constant) &rarr; 0 or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Locks or unlocks a file according to <em>locking_constant</em> (a logical <em>or</em> of the values in the table below). Returns <code>false</code> if File::LOCK_NB is specified and the operation would otherwise have blocked. Not available on all platforms.</p>

<p>Locking constants (in class <a href="File.html"><code>File</code></a>):</p>

<pre>LOCK_EX   | Exclusive lock. Only one process may hold an
          | exclusive lock for a given file at a time.
----------+------------------------------------------------
LOCK_NB   | Don&#39;t block when locking. May be combined
          | with other lock options using logical or.
----------+------------------------------------------------
LOCK_SH   | Shared lock. Multiple processes may each hold a
          | shared lock for a given file at the same time.
----------+------------------------------------------------
LOCK_UN   | Unlock.</pre>

<p>Example:</p>

<pre class="ruby"><span class="ruby-comment"># update a counter using write lock</span>
<span class="ruby-comment"># don&#39;t use &quot;w&quot; because it truncates the file before lock.</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;counter&quot;</span>, <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">RDWR</span><span class="ruby-operator">|</span><span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">CREAT</span>, <span class="ruby-value">0644</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_EX</span>)
  <span class="ruby-identifier">value</span> = <span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">rewind</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-node">&quot;#{value}\n&quot;</span>)
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">flush</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">truncate</span>(<span class="ruby-identifier">f</span>.<span class="ruby-identifier">pos</span>)
}

<span class="ruby-comment"># read the counter using read lock</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;counter&quot;</span>, <span class="ruby-string">&quot;r&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">flock</span>(<span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">LOCK_SH</span>)
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">read</span>
}
</pre>

                              <div class="method-source-code" id="flock-source">
            <pre>static VALUE
rb_file_flock(VALUE obj, VALUE operation)
{
    rb_io_t *fptr;
    int op[2], op1;
    struct timeval time;

    op[1] = op1 = NUM2INT(operation);
    GetOpenFile(obj, fptr);
    op[0] = fptr-&gt;fd;

    if (fptr-&gt;mode &amp; FMODE_WRITABLE) {
        rb_io_flush_raw(obj, 0);
    }
    while ((int)rb_thread_io_blocking_region(rb_thread_flock, op, fptr-&gt;fd) &lt; 0) {
        int e = errno;
        switch (e) {
          case EAGAIN:
          case EACCES:
#if defined(EWOULDBLOCK) &amp;&amp; EWOULDBLOCK != EAGAIN
          case EWOULDBLOCK:
#endif
            if (op1 &amp; LOCK_NB) return Qfalse;

            time.tv_sec = 0;
            time.tv_usec = 100 * 1000;  /* 0.1 sec */
            rb_thread_wait_for(time);
            rb_io_check_closed(fptr);
            continue;

          case EINTR:
#if defined(ERESTART)
          case ERESTART:
#endif
            break;

          default:
            rb_syserr_fail_path(e, fptr-&gt;pathv);
        }
    }
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-lstat" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          lstat &rarr; stat
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Like <a href="IO.html#method-i-stat"><code>File#stat</code></a>, but does not follow the last symbolic link; instead, returns a <a href="File/Stat.html"><code>File::Stat</code></a> object for the link itself:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">symlink</span>(<span class="ruby-string">&#39;t.txt&#39;</span>, <span class="ruby-string">&#39;symlink&#39;</span>)
<span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;symlink&#39;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">size</span>  <span class="ruby-comment"># =&gt; 47</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">lstat</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment"># =&gt; 11</span>
</pre>

                              <div class="method-source-code" id="lstat-source">
            <pre>static VALUE
rb_file_lstat(VALUE obj)
{
#ifdef HAVE_LSTAT
    rb_io_t *fptr;
    struct stat st;
    VALUE path;

    GetOpenFile(obj, fptr);
    if (NIL_P(fptr-&gt;pathv)) return Qnil;
    path = rb_str_encode_ospath(fptr-&gt;pathv);
    if (lstat_without_gvl(RSTRING_PTR(path), &amp;st) == -1) {
        rb_sys_fail_path(fptr-&gt;pathv);
    }
    return rb_stat_new(&amp;st);
#else
    return rb_io_stat(obj);
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-mtime" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          mtime  &rarr;  time
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the modification time for <em>file</em>.</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;testfile&quot;</span>).<span class="ruby-identifier">mtime</span>   <span class="ruby-comment">#=&gt; Wed Apr 09 08:53:14 CDT 2003</span>
</pre>

                              <div class="method-source-code" id="mtime-source">
            <pre>static VALUE
rb_file_mtime(VALUE obj)
{
    rb_io_t *fptr;
    struct stat st;

    GetOpenFile(obj, fptr);
    if (fstat(fptr-&gt;fd, &amp;st) == -1) {
        rb_sys_fail_path(fptr-&gt;pathv);
    }
    return stat_mtime(&amp;st);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-size" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">size</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="size-source">
            <pre>static VALUE
file_size(VALUE self)
{
    return OFFT2NUM(rb_file_size(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-truncate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          truncate(integer)    &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Truncates <em>file</em> to at most <em>integer</em> bytes. The file must be opened for writing. Not available on all platforms.</p>

<pre class="ruby"><span class="ruby-identifier">f</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;out&quot;</span>, <span class="ruby-string">&quot;w&quot;</span>)
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">syswrite</span>(<span class="ruby-string">&quot;1234567890&quot;</span>)   <span class="ruby-comment">#=&gt; 10</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">truncate</span>(<span class="ruby-value">5</span>)              <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-identifier">f</span>.<span class="ruby-identifier">close</span>()                  <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-constant">File</span>.<span class="ruby-identifier">size</span>(<span class="ruby-string">&quot;out&quot;</span>)           <span class="ruby-comment">#=&gt; 5</span>
</pre>

                              <div class="method-source-code" id="truncate-source">
            <pre>static VALUE
rb_file_truncate(VALUE obj, VALUE len)
{
    rb_io_t *fptr;
    struct ftruncate_arg fa;

    fa.pos = NUM2OFFT(len);
    GetOpenFile(obj, fptr);
    if (!(fptr-&gt;mode &amp; FMODE_WRITABLE)) {
        rb_raise(rb_eIOError, &quot;not opened for writing&quot;);
    }
    rb_io_flush_raw(obj, 0);
    fa.fd = fptr-&gt;fd;
    if ((int)rb_thread_io_blocking_region(nogvl_ftruncate, &amp;fa, fa.fd) &lt; 0) {
        rb_sys_fail_path(fptr-&gt;pathv);
    }
    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

